Johann Pardanaud
09/12/2023, 11:38 AMJohann Pardanaud
09/12/2023, 11:40 AMdave08
09/12/2023, 1:32 PMJohann Pardanaud
09/12/2023, 1:34 PMJohann Pardanaud
09/12/2023, 1:38 PMJohann Pardanaud
09/12/2023, 1:39 PMdave08
09/12/2023, 1:40 PMJohann Pardanaud
09/12/2023, 1:41 PMdave08
09/12/2023, 1:46 PMexpectThat(result).isValid(validator)
would be Soo much nicer, but then the isValid should try to produce similar output as Strikt does for it's soft assertion failures...dave08
09/12/2023, 1:48 PMdave08
09/12/2023, 1:48 PMJohann Pardanaud
09/12/2023, 1:49 PMJohann Pardanaud
09/12/2023, 1:49 PMdave08
09/12/2023, 1:50 PMJohann Pardanaud
09/12/2023, 1:52 PMdave08
09/12/2023, 1:57 PMdave08
09/12/2023, 1:59 PMexpectThat(result).and {
get(User::id).isXXX...
get(User::name).isXXX...
...
}
in the first test, and then for other tests I check just a certain field to make sure that the right record was returned.dave08
09/12/2023, 2:00 PMdave08
09/12/2023, 2:01 PMdave08
09/12/2023, 2:01 PMdave08
09/12/2023, 2:02 PMdave08
09/12/2023, 2:02 PMdave08
09/12/2023, 2:03 PMJohann Pardanaud
09/12/2023, 2:03 PMJohann Pardanaud
09/12/2023, 2:03 PMJohann Pardanaud
09/12/2023, 2:03 PMdave08
09/12/2023, 2:04 PMdave08
09/12/2023, 2:04 PMβΌ Expect that "The Enlightened take things Lightly":
β has length 5
found 35
β matches the regular expression /\d+/
found "The Enlightened take things Lightly"
β starts with "T"
Johann Pardanaud
09/12/2023, 2:05 PMJohann Pardanaud
09/12/2023, 2:05 PMJohann Pardanaud
09/12/2023, 2:05 PMdave08
09/12/2023, 2:06 PMval subject = "The Enlightened take things Lightly"
expectThat(subject) {
hasLength(5) // fails
matches(Regex("\\d+")) // fails
startsWith("T") // still evaluated and passes
}
dave08
09/12/2023, 2:06 PMdave08
09/12/2023, 3:08 PMdave08
09/12/2023, 3:09 PMdave08
09/12/2023, 3:10 PMJohann Pardanaud
09/12/2023, 3:51 PMdave08
09/12/2023, 3:51 PMJohann Pardanaud
09/12/2023, 3:53 PMJohann Pardanaud
09/12/2023, 3:53 PMJohann Pardanaud
09/12/2023, 3:54 PMdave08
09/12/2023, 3:55 PMJohann Pardanaud
09/12/2023, 3:56 PMdave08
09/12/2023, 3:57 PMlike snapshot testing everywhere else: with multiple tests π
dave08
09/12/2023, 4:00 PMhowever, I was also thinking about a configuration option forcing all the constraints to fail (edited)How would that help?
Johann Pardanaud
09/12/2023, 9:25 PMdave08
09/13/2023, 9:39 AMisNotNull { ... not null validation }
?Johann Pardanaud
09/13/2023, 9:43 AMJohann Pardanaud
09/13/2023, 9:43 AMdave08
09/13/2023, 9:46 AMJohann Pardanaud
09/13/2023, 9:47 AMValidator<String?> {
isNotNull()
isNotEmpty()
}
is easier to write and more readable than:
Validator<String?> {
isNotNull {
isNotEmpty()
}
}
also it means you can write:
Validator<String?> {
isNotEmpty()
}
which is a valid use case: you allow the string to be null, but if present you want it to be filledJohann Pardanaud
09/13/2023, 9:48 AMTrue, but in certain situations, you might forget to write isNotNull(), and shoot yourself in the foot... like when asserting in unit tests...This is something I have in mind, maybe with an Intellij plugin
dave08
09/13/2023, 9:53 AMJohann Pardanaud
09/13/2023, 9:54 AMJohann Pardanaud
09/13/2023, 9:56 AMdave08
09/13/2023, 9:57 AMdave08
09/13/2023, 9:58 AMJohann Pardanaud
09/13/2023, 10:01 AMdave08
09/13/2023, 10:06 AMEither<R, Nel<ConstraintViolation>>
instead of Success
and Failure
?dave08
09/13/2023, 10:07 AMJohann Pardanaud
09/13/2023, 10:25 AMAlso, the Arrow integration will provide anYes, otherwise it would be a bad integration πinstead ofEither<R, Nel<ConstraintViolation>>
andSuccess
?Failure
dave08
09/13/2023, 10:30 AM// In the tests code base... not for validation, only for test assertions on the object hierarchy returned.
val validator = Validator<Book, Book> { expected ->
// First the property, then the constraint, finally the message.
title.isNotEmpty().isEqualsTo(expected.title)
releaseDate.isEqualsTo(expected.releaseDate)
authors.startsWith(expected.authors.take(3)) // This would be more useful for urls that's ports change in tests when mock servers go up with different random port...
// Skip checking unimportant or volatile fields, or check inside the object hierarchy which wouldn't be possible with a normal assertEquals(...)
}
expectThat(result).isValid(validator, expectedBook)
dave08
09/13/2023, 10:31 AMJohann Pardanaud
09/13/2023, 10:50 AMisValid
method? Or about the content of the validator? If so, what part exactly?dave08
09/13/2023, 11:12 AMexpectThat(result).isValid(validator)
which isn't right... since a validator by itself won't check the expected state of the resulting object... and the validator isn't the same as one that would validate an object's state in production, because in production you have certain requirements on the data of the object, whereas in tests you're just comparing a resulting state to an expected one (ignoring certain fields, or treating others in special ways for the comparison you're interested in for that particular set of tests...)Johann Pardanaud
09/13/2023, 11:18 AMdave08
09/13/2023, 11:21 AMJohann Pardanaud
09/13/2023, 11:21 AMdave08
09/13/2023, 11:27 AMJohann Pardanaud
09/13/2023, 11:28 AMJohann Pardanaud
09/13/2023, 11:28 AMPoisonedYouth
09/17/2023, 2:38 PM