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.

QuarkusUnitTest: assertException shadows out setExpectedException

See original GitHub issue

In 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:closed
  • Created 4 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ge0ffreycommented, Feb 5, 2020

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.

1reaction
ge0ffreycommented, Feb 7, 2020

It won’t make this week, but it’s on my short term todo list.

Read more comments on GitHub >

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

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