You could write a custom matcher that calls assert softly
l
Lidonis Calhau
10/20/2021, 1:06 PM
I have seen in the doc how to build a custom matcher but it requires a boolean
I don't how to link it to assertSoftly
Do you have an example ?
Copy code
fun containFoo() = object : Matcher<String> {
override fun test(value: String) = MatcherResult(value.contains("foo"), "String $value should include foo", "String $value should not include foo")
}
s
sam
10/20/2021, 1:08 PM
The result would be whatever was in that function you wanted to create
sam
10/20/2021, 1:09 PM
I can make an example. Give me an hour or so
l
Lidonis Calhau
10/20/2021, 1:09 PM
ok thanks a lot :)
s
sam
10/20/2021, 2:12 PM
Copy code
fun customAssert() = Matcher<String> { foo ->
val error = try {
assertSoftly(foo) {
shouldNotEndWith("b")
length shouldBe 3
}
null
} catch (e: Throwable) {
e
}
MatcherResult(error == null, "should not have failed", "should have failed")
}