Kommander
A highly interoperable kotlin multiplatform assertion library
Usage
Simple usage is to just let your commander expect
something and let your IDE guide you in prompting what assertion you need to do with your expected assumption
package samples
import kommander.expect
import kommander.toBeGreaterThan
import kommander.toBeLessThan
import kotlin.test.Test
class PersonTest {
val person = Person(name = "John Doe", age = 30)
@Test
fun should_perform_basic_assertions() {
expect(person.name).toBe("John Doe")
expect(person.age).toBe(30)
}
@Test
fun should_perform_compound_assertion() {
expect(person.age) {
toBe(30)
toBeLessThan(50)
toBeGreaterThan(18)
toBeNonNull()
}
}
}
Content copied to clipboard
Setup: Gradle
dependencies {
implementation("tz.co.asoft:kommander-core:unspecified")
// - - - - - or - - - - -
implementation("tz.co.asoft:kommander-coroutines:unspecified")
}
Content copied to clipboard
Nullability
val name: String? = null
expect(name).toBeNull()
val age: Int = 0
expect(age).toBeNonNull()
Content copied to clipboard
Custom Assertions
You can create your custom assertions easily in kotlin as well
package samples
import kommander.Expect
import kommander.expect
import kommander.toBeGreaterThan
import kotlin.test.Test
class CustomAssertionsTest {
val person = Person(name = "Jane", age = 19)
fun Expect<Person>.toBeAnAdult() {
expect(value.age).toBeGreaterThan(18)
}
@Test
fun test_adulthood() {
expect(person).toBeAnAdult()
}
}
Content copied to clipboard
Api Reference
The full api reference of the kommander can be found at https://asoft-ltd.github.io/kommander
Support
There are multiple ways you can support this project
Star It
If you found it useful, just give it a star
Contribute
You can help by submitting pull request to available open tickets on the issues section
Report Issues
This makes it easier to catch bugs and offer enhancements required
Credits
-
andylamax - The author