`assertThatThrownBy.doesNotThrowAnyException()` fails when no exception is thrown
See original GitHub issueSummary
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:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top 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 >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
I agree
doesNotThrowAnyException
should not be available after callingassertThatThrownBy
.doesNotThrowAnyException
is meant to use withassertThatCode
as pointed out by @onacit, when we added it we did not realize it would be possible to use it afterassertThatThrownBy
.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 changeassertThatThrownBy
behavior that fails when none was thrown.We are already looking at it @HeZean but thanks!