Good Code
The good version gives the invalid input and expected error code, so a validation regression fails at the rule being protected.
Lesson 10
Write Kotlin tests that name the behavior, input fixture, and exact output contract.
class ReviewValidatorTest : StringSpec({
"rejects a blank title" {
// The fixture names the invalid input and expected error code.
val result = validate(ReviewInput(title = " ", score = 5))
result shouldBe ValidationError("title_blank")
}
})class ReviewValidatorTest : StringSpec({
"validates reviews" {
// Non-null assertion misses the validation contract callers use.
validate(ReviewInput(title = "", score = 5)) shouldNotBe null
}
})The good version gives the invalid input and expected error code, so a validation regression fails at the rule being protected.
The bad version only checks for a non-null result. It can pass while the validator returns the wrong error.