https://github.com/memoizr/assertk-core
A Kotlin-friendly wrapper for AssertJ
https://github.com/memoizr/assertk-core
Last synced: 3 months ago
JSON representation
A Kotlin-friendly wrapper for AssertJ
- Host: GitHub
- URL: https://github.com/memoizr/assertk-core
- Owner: memoizr
- License: apache-2.0
- Created: 2016-07-27T21:17:01.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-12-10T21:04:34.000Z (over 4 years ago)
- Last Synced: 2025-04-13T03:13:32.824Z (3 months ago)
- Language: Kotlin
- Homepage:
- Size: 381 KB
- Stars: 22
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/memoizr/assertk-core) [](https://jitpack.io/#memoizr/assertk-core) [](http://www.apache.org/licenses/LICENSE-2.0.html) [](https://codecov.io/gh/memoizr/assertk-core)
# AssertK - Fluent assertions for Kotlin
AssertK provides a Kotlin-friendly syntax for using the amazing AssertJ assertion framework.###Simple assertions
```kotlin
assert that Unit isEqualTo Unit
```you can use `assert that` or `expect that` interchangeably as `assert` tends to be a bit noisy when trying to autocomplete the statement.
```kotlin
expect that Any() isNotEqualTo Any()
expect that Any() _is notNull
expect that nullObject _is null
expect that anObject isInstance of()
expect that Any() describedAs "A labeled object" isInstance of()
```###Chained syntax
```kotlin
expect that Unit isNotEqualTo Any() isEqualTo Unit _is notNull isInstance of()
```###Block syntax
```kotlin
expect that Any() isSuchThat {
it _is notNull
it isInstance of()
it isNotEqualTo Unit
it isNotEqualTo Any()
}
```##Assertions on exceptions
###Chained syntax
```kotlin
expect thatExceptionIsThrownBy { failFunction() } hasMessageContaining "foo" hasCause Throwable()
```###Block syntax
```kotlin
expect thatExceptionIsThrownBy {
throw Throwable("exception foo", Throwable())
} and {
it hasMessage "exception foo"
it hasCause Throwable()
it hasCauseExactlyInstanceOf Throwable::class.java
it hasMessageContaining "foo"
it hasMessageStartingWith "ex"
it hasMessageEndingWith "foo"
}
```#Further Examples
##Iterable Assert
```kotlin
expect that myListOfInts hasSize 10 contains 3 startsWith 1
```
##Boolean Assert
```kotlin
expect that myBoolean _is false
```
##Float, Double, Int, Long Assert
```kotlin
expect that myFloat isGreaterThan otherFloat
expect that myInt _is notPositive isLessThan expectedResult
```
##Get it
```groovy
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
dependencies {
...
testCompile 'com.github.memoizr:assertk-core:0.1.0'
...
}
```
####License
Copyright 2016 memoizrLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.