Skip to content

Commit 588588e

Browse files
paynerbevant
authored andcommitted
Update and improve README.md
1 parent a765837 commit 588588e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

README.md

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
# assertk
22

3-
[![CircleCI](https://circleci.com/gh/willowtreeapps/assertk.svg?style=svg)](https://circleci.com/gh/willowtreeapps/assertk)[![Maven Central](https://img.shields.io/maven-central/v/com.willowtreeapps.assertk/assertk.svg)](https://search.maven.org/search?q=g:com.willowtreeapps.assertk)
3+
[![CircleCI](https://circleci.com/gh/willowtreeapps/assertk.svg?style=svg)](https://circleci.com/gh/willowtreeapps/assertk)
4+
[![Maven Central](https://img.shields.io/maven-central/v/com.willowtreeapps.assertk/assertk.svg)](https://search.maven.org/search?q=g:com.willowtreeapps.assertk)
45
[![Sonatype Snapshot](https://img.shields.io/nexus/s/https/oss.sonatype.org/com.willowtreeapps.assertk/assertk.svg)](https://oss.sonatype.org/content/repositories/snapshots/com/willowtreeapps/assertk/)
56

6-
assertions for kotlin inspired by assertj
7+
assertk is a fluent assertion library for Kotlin inspired by [AssertJ](https://github.com/assertj/assertj-core).
8+
9+
- [Documentation](https://willowtreeapps.github.io/assertk/assertk/assertk.assertions/index.html)
10+
11+
## Why another assertion library?
12+
13+
You might be asking, "If AssertJ already exists, why create another library?". It's true, assertk is very similar to AssertJ. But assertk is written in Kotlin so it has one major advantage: extension methods. This makes adding your own assertion methods far simpler.
14+
15+
See [Custom Assertions](#custom-assertions) below to find out how to do this.
716

817
## Setup
918

@@ -64,13 +73,15 @@ Since null is a first-class concept in kotlin's type system, you need to be expl
6473
val nullString: String? = null
6574
assertThat(nullString).hasLength(4)
6675
```
76+
6777
will not compile, since `hasLength()` only makes sense on non-null values. You can chain `isNotNull()` to handle this.
6878

6979
```kotlin
7080
val nullString: String? = null
7181
assertThat(nullString).isNotNull().hasLength(4)
7282
// -> expected to not be null
7383
```
84+
7485
This will first ensure the string is not null before running any other checks.
7586

7687
### Multiple assertions
@@ -102,6 +113,7 @@ assertAll {
102113
```
103114

104115
### Iterable/List Assertions
116+
105117
You can assert on the contents of an `Iterable/List` with the various `contains*` functions. They have different
106118
semantics as follows:
107119

@@ -116,7 +128,7 @@ semantics as follows:
116128

117129
### Extracting data
118130

119-
There's a few ways you extract the data you want to assert on. While you can do this yourself before calling the
131+
There's a few ways you extract the data you want to assert on. While you can do this yourself before calling the
120132
assertion, these methods will add the extra context to the failure message which can be helpful.
121133

122134
The simplest way is with `prop()`. It will take a property (or function, or a name and a lambda) and return an
@@ -163,6 +175,7 @@ assertThat {
163175
```
164176

165177
This method also allows you to assert on successfully returned values.
178+
166179
```kotlin
167180
assertThat { 1 + 1 }.isSuccess().isNegative()
168181
// -> expected to be negative but was:<2>
@@ -241,4 +254,5 @@ The general rule of thumb is to prefer building out of the existing assertions u
241254
error message.
242255

243256
## Contributing to assertk
244-
Contributions are more than welcome! Please see the [Contributing Guidelines](https://github.com/willowtreeapps/assertk/blob/master/Contributing.md) and be mindful of our [Code of Conduct](https://github.com/willowtreeapps/assertk/blob/master/code-of-conduct.md).
257+
258+
Contributions are more than welcome! Please see the [Contributing Guidelines](https://github.com/willowtreeapps/assertk/blob/main/Contributing.md) and be mindful of our [Code of Conduct](https://github.com/willowtreeapps/assertk/blob/main/code-of-conduct.md).

0 commit comments

Comments
 (0)