QuarkusUnitTest: assertException shadows out setExpectedException
See original GitHub issueIn the testcase below, this unit test is red (which is correct):
new QuarkusUnitTest()
...
.setExpectedException(ArithmeticException.class); // RED, which is correct
This unit test is green (which is also correct):
new QuarkusUnitTest()
...
.assertException(throwable -> {
assertTrue(throwable instanceof IllegalArgumentException);
assertTrue(throwable.getMessage().contains("scanAnnotatedClasses"));
}); // GREEN, which is correct
Obviously, combining both of these (a green and a red test) should give me a red result. But this test is green (which is wrong):
new QuarkusUnitTest()
...
.setExpectedException(ArithmeticException.class);
.assertException(throwable -> {
assertTrue(throwable instanceof IllegalArgumentException);
assertTrue(throwable.getMessage().contains("scanAnnotatedClasses"));
}); // GREEN, which is wrong! There is no ArithmeticException!
Full source code:
public class OptaPlannerProcessorIllegalXMLTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setExpectedException(IllegalArgumentException.class)
.overrideConfigKey("quarkus.optaplanner.solver-config-xml",
"io/quarkus/optaplanner/illegalScanAnnotatedSolverConfig.xml")
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addAsResource("io/quarkus/optaplanner/illegalScanAnnotatedSolverConfig.xml"))
.setExpectedException(ArithmeticException.class) // Doesn't happen
.assertException(throwable -> {
assertTrue(throwable instanceof IllegalArgumentException);
assertTrue(throwable.getMessage().contains("scanAnnotatedClasses"));
});
@Test
public void scanAnnotatedClasses() {
// Should not be called, deployment exception should happen first
Assertions.fail();
}
}
Proposal A) Check both (do not shadow) Proposal B) Fail fast if both are used together.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Quarkus v1.3.0.CR1 release notes (2020-03-06) | LibHunt
... #7000 - QuarkusUnitTest: assertException shadows out setExpectedException; #6997 - Improve OIDC multi-tenancy and "web-app" ...
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 Free
Top 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
And with B) we can always go to A) without breaking backwards compatibility. Not so visa versa. When in doubt, leave it out. I’ll take a look at doing B) later this week.
It won’t make this week, but it’s on my short term todo list.