https://kotlinlang.org logo
#random
Title
# random
c

Colton Idle

12/11/2023, 5:47 PM
I'm using google truth for test assertions. Is my googling failing me, or is there no way to "fail" a test?
Copy code
when (val foo = something) {
    is One -> fail() <===== I just want to fail if foo is of type One
    is Two -> assertThat(bar).isNotEmpty()
    null -> TODO()
}
t

thanksforallthefish

12/12/2023, 7:00 AM
not that I use truth, but does not https://github.com/google/truth/issues/351 work? otherwise just go hacking mode, assert true is false with a custom message 🤷
c

Colton Idle

12/12/2023, 7:11 AM
nope. no dice. I guess assert true is false it is... lmao
t

thanksforallthefish

12/12/2023, 7:22 AM
there is
Truth.assert_().fail()
, but I like hacks 😄
Copy code
import com.google.common.truth.Truth

Truth.assert_().withMessage("something something").fail()
though it prints the message twice to me
🤯 2
k

Klitos Kyriacou

12/12/2023, 9:04 AM
You could always just use JUnit's fail().
👍 2
👍🏾 1