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

QuarkusTest does not run @BeforeEach method of outer class when using @Nested test classes #23947

Closed
Emmeral opened this issue Feb 24, 2022 · 2 comments · Fixed by #24172
Closed
Labels
area/testing kind/bug Something isn't working
Milestone

Comments

@Emmeral
Copy link
Contributor

Emmeral commented Feb 24, 2022

Describe the bug

Given the following test class:

import static org.junit.jupiter.api.Assertions.assertEquals;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

@QuarkusTest
public class DemonstratorTest {

    String outerValue;

    @BeforeEach
    void setUp() {
        outerValue = "outer";
    }

    @Nested
    public class NestedClass{

        String innerValue;

        @BeforeEach
        void setUp() {
            innerValue = "inner";
        }

        @Test
        void test() {
            assertEquals("inner", innerValue);
            assertEquals("outer", outerValue);
        }
    }
}

Expected behavior

Both the outer and the inner @BeforeEach method are called before the test. Therefore the test succeeds.

Actual behavior

The test fails because outerValue is actual null. If the @QuarkusTest annotation is removed from the outer class, the test succeeds as expected.

How to Reproduce?

Run the test above.

Output of uname -a or ver

No response

Output of java -version

openjdk version "11.0.13" 2021-10-19 OpenJDK Runtime Environment Temurin-11.0.13+8 (build 11.0.13+8) OpenJDK 64-Bit Server VM Temurin-11.0.13+8 (build 11.0.13+8, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.7.0.Final

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

Apache Maven 3.8.4

Additional information

If the public modifier of the outer class is removed, the test does not run at all and the following stacktrace is produced:

java.lang.NoSuchMethodException: my.package.DemonstratorTest.<init>()

	at java.base/java.lang.Class.getConstructor0(Class.java:3349)
	at java.base/java.lang.Class.getConstructor(Class.java:2151)
	at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:987)
	at io.quarkus.test.junit.QuarkusTestExtension.interceptBeforeEachMethod(QuarkusTestExtension.java:796)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
	...
@Emmeral Emmeral added the kind/bug Something isn't working label Feb 24, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Feb 24, 2022

/cc @geoand

Sgitario added a commit to Sgitario/quarkus that referenced this issue Mar 8, 2022
Sgitario added a commit to Sgitario/quarkus that referenced this issue Mar 8, 2022
@Sgitario
Copy link
Contributor

Sgitario commented Mar 8, 2022

Proposed solution in #24172

famod pushed a commit to Sgitario/quarkus that referenced this issue Mar 8, 2022
Sgitario added a commit to Sgitario/quarkus that referenced this issue Mar 9, 2022
@quarkus-bot quarkus-bot bot added this to the 2.8 - main milestone Mar 9, 2022
@gsmet gsmet modified the milestones: 2.8 - main, 2.7.5.Final Mar 14, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants