-
Notifications
You must be signed in to change notification settings - Fork 0
Testing
- Backticked function names are faster to write than
@DisplayName("blah-blah-blah")followingvoid blahBlahBlah()in Java. - Infix assertions from Kotest are faster to write and read.
Tests already written in Java are gradually migrated to Kotlin.
We do use Java for tests when we need to test Java-specific API.
Please use the pattern <SubjectClassName>Spec. We use the Spec suffix to highlight the fact that tests are real and actionable specification of the code.
If it's not an abstract base to be used from other modules, do make the test suite class internal.
We use the annotation instead of a backticked class name for the following reasons:
- It's easier to search in IDE.
- Tests and production code come close in the alphabetical order.
- The value of annotation as a string gives you more options in writing, including backticking the name of the test subject.
- It's easier to reference a test suite in writing if it
MyClassSpecrather than'MyClass' should.
It should look like this:
@DisplayName("`MyClass` should")
internal class MyClassSpec {
// ...
}Do you backicked names for nested classes with the following wrapping:
@DisplayName("`Type` extensions should")
internal class TypeExtsSpec {
@Nested inner class
`Obtain simple type name` {
// ...
}
}This way it's easier to read the goal of the nested class when scanning the code from top to bottom.
Start the text of the name with a capital letter to help distinguish nested classes from test functions in the list of test results.