Assert not null or specific object type for further assertions on an object
See original GitHub issueSay:
val obj: Person? = ....
obj shouldNotBeNullAnd {
it.name shouldBe "b"
it.age shouldNotBe 43
}
This should and assert that Person is not null, and provide the ability to check the non-null result. This could also probably be done with Kotlin Contracts, just by doing a null assertion before other assertions. The difference between this and result!! should { }
is that the previous is an actual assertion and the latter is a runtime failure.
Something similar could possibly done for shouldBeInstanceOf
to make assertions on the already casted instance.
Issue Analytics
- State:
- Created 5 years ago
- Comments:21 (21 by maintainers)
Top Results From Across the Web
What is the difference between assert object!=null and Assert ...
assert object !=null; is a single java statement but Assert.assertNotNull(object) will result in calling of Multiple functions of TestNG, ...
Read more >Program: Assertion method Assert.assertNotNull() example.
Assert class provides a set of assertion methods useful for writing tests. Assert.assertNotNull() methods checks that the object is null or not.
Read more >Assert that an Object is from a Specific Type | Baeldung
In this article, we'll explore how we can verify that an object is of a specific type. We'll be looking at different testing...
Read more >Junit Assert & AssertEquals with Example - Guru99
In this tutorial, you will learn, JUnit Assert methods like Boolean, Null object, Identical, Assert Equals, Assert Array Equals, ...
Read more >Assert (JUnit API)
A set of assertion methods useful for writing tests. Only failed assertions are recorded. These methods can be used directly: Assert.assertEquals(.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dave08 As this discussion won’t be including Kotlin Contracts for now, please submit a feature request to add a lambda parameter to
shouldBeInstanceOf
for us to discuss it better.For now I’ll be closing this, as this feature was implemented and merged in the
3.3
branch.shouldBeInstanceOf<Foo>
is already reified. It’s a currently unsupported feature 😕