Book Image

Programming Kotlin

Book Image

Programming Kotlin

Overview of this book

Quickly learn the fundamentals of the Kotlin language and see it in action on the web. Easy to follow and covering the full set of programming features, this book will get you fluent in Kotlin for Android.
Table of Contents (20 chapters)
Programming Kotlin
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

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 
          "".length shouldBe 0     
  ...