Skip to content

[JUnit 5+] @Nested classes do not run in the container #773

@nlisker

Description

@nlisker
@ExtendWith(ArquillianExtension.class)
public class ArqSuitTest {

	@Deployment
	public static WebArchive createDeployment() {
		return ShrinkWrap.create(WebArchive.class, "1.war");
	}

	static int i;

	@BeforeEach
	void be() {
		System.out.println("be " + i++);
	}

	@Nested
	class Nested {

		@BeforeEach
		void nbe() {
			System.out.println("nbe " + i++);
		}

		@Test
		void nb() {
			System.out.println("nb " + i++);
		}
	}

	@Test
	void b() {
		System.out.println("b " + i++);
	}
}

prints

16:57:13,250 INFO  [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0010: Deployed "1.war" (runtime-name : "1.war")
16:57:13,898 INFO  [org.jboss.arquillian.testenricher.cdi.container.BeanManagerProducer] (default task-2) BeanManager not found.
16:57:14,013 INFO  [stdout] (default task-2) be 0

16:57:14,025 INFO  [stdout] (default task-2) b 1

be 0
nbe 1
nb 2

Showing that the static field isn't the same one for nested classes since the nested class runs outside of the container.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions