snowdrop-zen / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
1 stars 0 forks source link

@Nested not working in @QuarkusTest #361

Closed snowdrop-bot closed 3 years ago

snowdrop-bot commented 3 years ago

Describe the bug

@Nested classes are not working properly in @QuarkusTest.

Expected behavior

@Nested tests run without throwing exception

Actual behavior

Exception is thrown: java.lang.RuntimeException: Could not find method public void junit.NestedTest.GreetingResourceTest.beforeEach() on test class

To Reproduce

Steps to reproduce the behavior:

  1. Run mvn io.quarkus:quarkus-maven-plugin:1.13.7.Final:create -DprojectGroupId="junit.NestedTest" -DprojectArtifactId=NestedTest -DprojectVersion=1.0-SNAPSHOT
  2. Add class
package junit.NestedTest;

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 GreetingResourceTest {

    @BeforeEach
    public void beforeEach() {
        System.out.println("beforeEach");
    }

    @Test
    public void test() {
        System.out.println("test");
    }

    @Nested
    class Nested1 {
        @BeforeEach
        public void beforeEach() {
            System.out.println("beforeEach1");
        }

        @Test
        public void test() {
            System.out.println("test1");
        }

        @Nested
        class Nested2 {
            @BeforeEach
            public void beforeEach() {
                System.out.println("beforeEach2");
            }

            @Test
            public void test() {
                System.out.println("test2");
            }
        }
    }
}
  1. Run mvn test

Environment (please complete the following information):

Output of uname -a or ver

Microsoft Windows [Version 10.0.18363.1500]

Output of java -version

java version "1.8.0_201" Java(TM) SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot(TM) Client VM (build 25.201-b09, mixed mode)

GraalVM version (if different from Java)

Quarkus version or git rev

1.13.7

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

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

Additional context

https://github.com/quarkusio/quarkus/blob/645c35fcbf1c0a27ff782e39dbf8407ebbb818cd/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java#L949 This line skips the enclosing class of the nested class.

Reported also on stackoverflow: https://stackoverflow.com/questions/67932551/could-not-find-beforeeach-setup-method-on-nested-test-class-in-quarkustest/67986570#67986570


https://github.com/quarkusio/quarkus/issues/17975


$upstream:17975$