Anyone use google truth assertion library? I can't...
# random
c
Anyone use google truth assertion library? I can't figure out how to assert that an object is of a specific type. Not possible?
e
Copy code
Truth.assertThat(...).isInstanceOf(...)
but IMO other assertion libraries like Kluent are more fluent to use from Kotlin, with contracts and all
c
haven't heard of kluent. may give that a try. thanks as always @ephemient
e
c
On the same topic (im getting a bit more exposure to testing). Are tests without assertions "bad". e.g. There are some tests im working with that dont have assertions, but they're mostly there to make sure the calling code doesn't throw an exception.
s
I don't think tests without assertions are bad, at least. We have tests for our `@Serializable`s that, given a JSON string, gets deserialized. It would throw if the types changed to something that couldn't be deserialized from the provided JSON.
As long as the tests fail if something breaks the contracts, then I'd say you're good, be that through assertions or exceptions, or timeouts or whathaveyou.
👍 1
k
Some static code analysers complain that "The test should make an assertion" in such cases. For those, one way to shut them up is to add
shouldNotThrow { ... }
(or your assertion library's equivalent) around your code.
e
it's better to leave some breadcrumbs, either in the test failure message or stacktrace, or at least comments in the code, with additional context about failures
s
Sure, you could do something like
try { ... } catch (SomeException) { fail("Failed because ...") }
.
188 Views