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.

`assertThatThrownBy.doesNotThrowAnyException()` fails when no exception is thrown

See original GitHub issue

Summary

Duplicate of https://github.com/assertj/assertj-core/issues/1787 because that is closed:

Example


    fun thisFunctionDoesNothing() {
        println("i did nothing")
    }

    @Test
    fun `this test should not fail, unfortunately it does`() {
        assertThatThrownBy { thisFunctionDoesNothing() }.doesNotThrowAnyException()
    }

And i get the exception:

Expecting code to raise a throwable.
java.lang.AssertionError: 
Expecting code to raise a throwable.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
joel-costigliolacommented, Mar 12, 2022

I agree doesNotThrowAnyException should not be available after calling assertThatThrownBy. doesNotThrowAnyException is meant to use with assertThatCode as pointed out by @onacit, when we added it we did not realize it would be possible to use it after assertThatThrownBy.

Having said that, we think it is natural for assertThatThrownBy to expect an exception to be thrown (that’s the point of this method) so we won’t change assertThatThrownBy behavior that fails when none was thrown.

0reactions
joel-costigliolacommented, Mar 14, 2022

We are already looking at it @HeZean but thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

assertThatThrownBy.doesNotThrowAnyException() fails when ...
I think the failure came from the assertThatThrownBy not from the doesNotThrowAnyException . In code,. Assertions.assertThatThrownBy(() -> { // ...
Read more >
How to test that no exception is thrown? - java - Stack Overflow
Just test your functionality: if an exception is thrown the test will automatically fail. If no exception is thrown, your tests will all...
Read more >
AssertJ Exception Assertions - Baeldung
Using Java 8, we can do assertions on exceptions easily, by leveraging AssertJ and lambda expressions. 3.1. Using assertThatThrownBy().
Read more >
Assertions (AssertJ fluent assertions 3.12.0 API)
The main difference with assertThatThrownBy(ThrowingCallable) is that this method does not fail if no exception was thrown. Example : ThrowingCallable boomCode ...
Read more >
Assertions (AssertJ fluent assertions 3.22.0 API) - javadoc.io
Modifier and Type Method Description static Condition allOf​(Iterable> conditions) Creates a new AllOf static Condition allOf​(Condition... conditions) Creates a new AllOf static Condition anyOf​(Iterable> conditions) Creates...
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