Anyone use google truth assertion library? I can't...
# random
Anyone use google truth assertion library? I can't figure out how to assert that an object is of a specific type. Not possible?
Copy code
but IMO other assertion libraries like Kluent are more fluent to use from Kotlin, with contracts and all
haven't heard of kluent. may give that a try. thanks as always @ephemient
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.
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
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.
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
Sure, you could do something like
try { ... } catch (SomeException) { fail("Failed because ...") }