Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JUnit @Nested with @QuarkusTest with @BeforeEach on Root-Class fails (Since 2.2.1.Final) #19843

Closed
vonatzigenc opened this issue Sep 1, 2021 · 3 comments · Fixed by #19921
Closed
Assignees
Labels
Milestone

Comments

@vonatzigenc
Copy link
Contributor

Describe the bug

The error is present only since the upgrade from 2.2.0.CR1 to 2.2.1.Final

If there is a @BeforeEach at the top level in a test with @Nested classes, only the first test runs through. The rest fail due to an IllegalArgumentException.

The error occurs from the second test on, no matter if multiple @Nested with one test each or one @Nested class with multiple tests.

Example multiple Nested

@QuarkusTest
public class NestedQuarkusTest {

    @BeforeEach
    void generalBeforeEach() {
    }

    @Nested
    class Foo {
        @Test
        void check() {
            Assertions.assertTrue(true);
        }
    }

    @Nested
    class Bar {
        @Test
        void check() {
            Assertions.assertTrue(true);
        }
    }

}

Example one Nested with multiple tests

@QuarkusTest
public class OneNestedQuarkusTestWithBeforeEach {
   
    @BeforeEach
    void generalBeforeEach() {
    }

    @Nested
    class Foo {
        @Test
        void checkA() {
            Assertions.assertTrue(true);
        }

        @Test
        void checkB() {
            Assertions.assertTrue(true);
        }
    }

}

Expected behavior

@BeforeEach should be performed for each test and the tests above should pass.

Actual behavior

java.lang.IllegalArgumentException: object is not an instance of declaring class

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:1084)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptBeforeEachMethod(QuarkusTestExtension.java:905)
	...

In io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:1084) the @BeforeEach method is invoked on the nested class instead of the "root class".

How to Reproduce?

Reproducer: https://github.com/vonatzigenc/reproducer-nested-quarkustest

Run tests:

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.2.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.1

Additional information

No response

@vonatzigenc vonatzigenc added the kind/bug Something isn't working label Sep 1, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Sep 1, 2021

/cc @geoand

@famod famod self-assigned this Sep 1, 2021
@famod
Copy link
Member

famod commented Sep 1, 2021

I know what's going on...sigh

Thanks for reporting!

@famod
Copy link
Member

famod commented Sep 1, 2021

I have a fix, will send a PR in the next two days.

@quarkus-bot quarkus-bot bot added this to the 2.3 - main milestone Sep 6, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Sep 6, 2021
@gsmet gsmet modified the milestones: 2.3 - main, 2.2.2.Final Sep 6, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Sep 6, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants