Unit tests with kotlin
Using JUnit.
Dependencies
How to build
bash
gradle buildHow to run
bash
gradle runHow to test
bash
gradle testNoteworthy
- This is a simpler gradle setup compared to the first example.
- Unlike kotlin script (.kts) it uses default groovy scripting for project configuration. I'ts quite similar to .kts scripts but be aware of the differences.
- There is no wrapper, no specified java version, therefore the build becomes dependent of the build machine. Fix that as an exercise.
- The code convention in kotlin is CamelCase, following pretty much what java convention says. It's not mandatory, as you can see in the jazz on files in these example projects. But follow the code conventions, they help you to create unexciting, boring and previsible projects. The enterprise way.
- Hamcrest and Mockito are pretty common libraries used with junit, so they are sampled here. Some functions those libraries have are reserved words in kotlin and must be escaped with backticks (`) to work as expected.