question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assert not null or specific object type for further assertions on an object

See original GitHub issue

Say:

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:closed
  • Created 5 years ago
  • Comments:21 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
LeoColmancommented, Jan 21, 2019

@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.

1reaction
LeoColmancommented, Jan 21, 2019

shouldBeInstanceOf<Foo> is already reified. It’s a currently unsupported feature 😕

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found