Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using Mockito with Kotlin

License

NotificationsYou must be signed in to change notification settings

mockito/mockito-kotlin

Repository files navigation

DownloadNexus Snapshot

A small library that provides helper functions to work withMockito in Kotlin.

Install

Mockito-Kotlin is available on Maven Central.For Gradle users, add the following to yourbuild.gradle, replacingx.x.x with the latest version:

testImplementation"org.mockito.kotlin:mockito-kotlin:x.x.x"

Example

A test using Mockito-Kotlin typically looks like the following:

@TestfundoAction_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 theWiki.

Building

Mockito-Kotlin is built with Gradle.

  • ./gradlew build builds and tests the project
  • ./gradlew publishToMavenLocal installs the maven artifacts in your local repository
  • ./gradlew check runs the test suite (See Testing below)

Versioning

Mockito-Kotlin roughly follows SEMVER

Testing

Mockito-Kotlin's test suite is located in a separatetests module,to allow running the tests using several Kotlin versions whilst stillkeeping the base module at a recent version.

  • ./gradlew check runs the checks including tests.

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,add the-PtestKotlinVersion=1.2.3 argument to the Gradle invocation while running the tests.

Acknowledgements

mockito-kotlin was created and developed bynhaarman@ after which the repository was integrated into the official Mockito GitHub organization.We would like to thank Niek for the original idea and extensive work plus support that went intomockito-kotlin.

About

Using Mockito with Kotlin

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors53


[8]ページ先頭

©2009-2025 Movatter.jp