Writing JUnit tests in Kotlin

If you've any experience with Java development, you've heard of or most probably worked with JUnit. It is a testing framework, for Java (as well as Kotlin).

Typically unit tests are created in a separate source folder than real source codes, to keep it separated. The standard Maven/Gradle convention uses src/main for real codes (Java/Kotlin files or classes) and src/test for test classes. The following screenshot shows the structure for the project we're using in this book:

Before beginning to write test cases we've to add the following Gradle dependencies:

 testCompile 'junit:junit:4.12' testCompile "org.mockito:mockito-core:1.9.5" ...

Get Reactive Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.