This document describes a protocol and principles to create tests that matter and will be useful not only to increase the coverage of the whole application but also to ensure stability and quality.
Like in most of the other platforms, we can implement several kinds of tests:
Each of them has its purpose and responsibilities.
Unit Tests intend to isolate small parts of the program to ensure it works as expected.
Some examples of tests we can perform are:
Behavioral tests case by spying and/or mocking a specific internal component class. In these tests, the data is unimportant because we only inspect the program's behavior.
For example:
class A(val b: B, val c: C) {
fun doSomething() {
b.invoke()
c.invoke()
}
}
class TestA {
test("When calling A.doSomething B is invoked and then C") {
a.doSomething()
verifySequence {
b.invoke()
c.invoke()
}
}
}
Data tests validate the consistency of program output with its input. The program's behavior is less important in these tests because we check that the result follows our expectations.
For example:
object A {
fun validate(b: B): Boolea = b.isValid
}
class TestA {
test("validate will return true if B is valid") {
val b = B(valid = true)
A.validate(b) shouldBe true
}
}