Choosing a spec
In the first test that we wrote, we extended a class called FunSpec
, which is just one example of what KotlinTest calls a spec. A spec, or style, is just the manner in which the tests are laid out in the class files. There are several different specs available, and which one you use is simply a matter of personal preference. The FunSpec
class is the style most similar to the old preannotation JUnit style, which readers from a Java background may be familiar with.
The rest of this section will cover the various specs that are available for you to choose from. The first alternative style to the FunSpec
class is FlatSpec
. This forces the user to use the word should
in the test names. This might appeal to developers who like uniformity in the testing names:
class MyTests : FlatSpec() { init { "String.length" should "return the length of the string" { "hello".length shouldBe 5 "...