commit | 1e505f00d0f1034a36f736a6703d63d70bc3156c | [log] [tgz] |
---|---|---|
author | Niek Haarman <haarman.niek@gmail.com> | Sun Sep 08 09:55:19 2019 +0200 |
committer | Niek Haarman <haarman.niek@gmail.com> | Sun Sep 08 09:55:19 2019 +0200 |
tree | 792846fd5e403b99b2cee39c55acae2519351b64 | |
parent | 4bcf696553bc866508aeac5e1ebe28b810ac667d [diff] |
Actually test against multiple Kotlin versions
A small library that provides helper functions to work with Mockito in Kotlin.
Mockito-Kotlin is available on Maven Central and JCenter. For Gradle users, add the following to your build.gradle
, replacing x.x.x
with the latest version:
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:x.x.x"
A test using Mockito-Kotlin typically looks like the following:
@Test fun doAction_doesSomething(){ /* Given */ val mock = mock<MyClass> { on { getText() } doReturn "text" } val classUnderTest = ClassUnderTest(mock) /* When */ classUnderTest.doAction() /* Then */ verify(mock).doSomething(any()) }
For more info and samples, see the Wiki.
Mockito-Kotlin is built with Gradle.
./gradlew build
builds the project./gradlew publishToMavenLocal
installs the maven artifacts in your local repository./gradlew assemble && ./gradlew test
runs the test suite (See Testing below)Mockito-Kotlin roughly follows SEMVER; version names are parsed from git tags using git describe
.
Mockito-Kotlin's test suite is located in a separate tests
module, to allow running the tests using several Kotlin versions whilst still keeping the base module at a recent version.
Testing thus must be done in two stages: one to build the base artifact to test against, and the actual execution of the tests against the built artifact:
./gradlew assemble
builds the base artifact./gradlew test
runs the tests against the built artifact.Usually it is enough to test only using the default Kotlin versions; CI will test against multiple versions. If you want to test using a different Kotlin version locally, set an environment variable KOTLIN_VERSION
and run the tests.