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

JUnit5 ParameterizedTest in Container #526

Open
kifj opened this issue Jan 8, 2024 · 1 comment
Open

JUnit5 ParameterizedTest in Container #526

kifj opened this issue Jan 8, 2024 · 1 comment

Comments

@kifj
Copy link
Contributor

kifj commented Jan 8, 2024

Issue Overview

Running a Junit5 parametrized test in the container results in repeated execution of all tests as many times as there are parameters provided.

Expected Behaviour

Each test case is only executed once.

Current Behaviour
Steps To Reproduce

a test class like

@ExtendWith(ArquillianExtension.class)
public class ParameterTest {
  private final static Logger LOG = LoggerFactory.getLogger(ParameterTest.class);

  @Deployment
  public static Archive<?> createTestArchive() {
    return ShrinkWrap.create(WebArchive.class, "test.war").addClasses(ParameterTest.class);
  }
  
  @BeforeEach
  public void setup() {
    LOG.debug("setup");
  }

  @ParameterizedTest
  @ValueSource(ints = { 1, 2, 3, 4, 5 })
  public void testInts(int value) {
    LOG.debug("testInts: value={}", value);
  }
}

results in test execution

19:47:05,243 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0027: Starting deployment of "test.war" (runtime-name: "test.war")
19:47:05,616 INFO  [org.wildfly.extension.micrometer] (MSC service thread 1-2) WFLYMMTREXT0002: Micrometer Subsystem is processing deployment
19:47:05,625 WARN  [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0013: Deployment test.war contains Jakarta Contexts and Dependency Injection annotations but no bean archive was found (no beans.xml or class with bean defining annotations was present).
19:47:05,660 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 107) WFLYUT0021: Registered web context: '/test' for server 'default-server'
19:47:05,683 INFO  [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0010: Deployed "test.war" (runtime-name : "test.war")
19:47:06,193 INFO  [org.jboss.arquillian.testenricher.cdi.container.BeanManagerProducer] (default task-1) BeanManager not found.
19:47:06,251 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,266 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=1
19:47:06,280 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,280 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=2
19:47:06,283 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,283 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=3
19:47:06,286 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,286 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=4
19:47:06,292 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,293 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=5
19:47:06,359 INFO  [org.jboss.arquillian.testenricher.cdi.container.BeanManagerProducer] (default task-1) BeanManager not found.
19:47:06,363 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,363 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=1
19:47:06,366 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,366 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=2
19:47:06,369 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,370 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=3
19:47:06,372 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,373 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=4
19:47:06,376 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,377 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=5
19:47:06,406 INFO  [org.jboss.arquillian.testenricher.cdi.container.BeanManagerProducer] (default task-2) BeanManager not found.
19:47:06,410 DEBUG [x1.stomp.test.ParameterTest] (default task-2) setup
19:47:06,411 DEBUG [x1.stomp.test.ParameterTest] (default task-2) testInts: value=1
19:47:06,415 DEBUG [x1.stomp.test.ParameterTest] (default task-2) setup
19:47:06,415 DEBUG [x1.stomp.test.ParameterTest] (default task-2) testInts: value=2
19:47:06,419 DEBUG [x1.stomp.test.ParameterTest] (default task-2) setup
19:47:06,419 DEBUG [x1.stomp.test.ParameterTest] (default task-2) testInts: value=3
19:47:06,424 DEBUG [x1.stomp.test.ParameterTest] (default task-2) setup
19:47:06,426 DEBUG [x1.stomp.test.ParameterTest] (default task-2) testInts: value=4
19:47:06,428 DEBUG [x1.stomp.test.ParameterTest] (default task-2) setup
19:47:06,429 DEBUG [x1.stomp.test.ParameterTest] (default task-2) testInts: value=5
19:47:06,458 INFO  [org.jboss.arquillian.testenricher.cdi.container.BeanManagerProducer] (default task-2) BeanManager not found.
19:47:06,462 DEBUG [x1.stomp.test.ParameterTest] (default task-2) setup
19:47:06,462 DEBUG [x1.stomp.test.ParameterTest] (default task-2) testInts: value=1
19:47:06,466 DEBUG [x1.stomp.test.ParameterTest] (default task-2) setup
19:47:06,467 DEBUG [x1.stomp.test.ParameterTest] (default task-2) testInts: value=2
19:47:06,473 DEBUG [x1.stomp.test.ParameterTest] (default task-2) setup
19:47:06,474 DEBUG [x1.stomp.test.ParameterTest] (default task-2) testInts: value=3
19:47:06,476 DEBUG [x1.stomp.test.ParameterTest] (default task-2) setup
19:47:06,476 DEBUG [x1.stomp.test.ParameterTest] (default task-2) testInts: value=4
19:47:06,478 DEBUG [x1.stomp.test.ParameterTest] (default task-2) setup
19:47:06,479 DEBUG [x1.stomp.test.ParameterTest] (default task-2) testInts: value=5
19:47:06,514 INFO  [org.jboss.arquillian.testenricher.cdi.container.BeanManagerProducer] (default task-1) BeanManager not found.
19:47:06,521 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,522 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=1
19:47:06,525 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,526 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=2
19:47:06,530 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,532 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=3
19:47:06,538 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,538 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=4
19:47:06,542 DEBUG [x1.stomp.test.ParameterTest] (default task-1) setup
19:47:06,542 DEBUG [x1.stomp.test.ParameterTest] (default task-1) testInts: value=5
19:47:06,564 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 107) WFLYUT0022: Unregistered web context: '/test' from server 'default-server'
19:47:06,576 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0028: Stopped deployment test.war (runtime-name: test.war) in 13ms
Additional Information

Test output in IDE or Maven shows that there are 5 executions, which value 1..5. In fact each test is run 5 times which all parameter values again.

RunAsClient executes each test only once.

@kifj
Copy link
Contributor Author

kifj commented Jan 8, 2024

Example build with JDK 21, Arquillian 1.8.0 on Wildfly 30 - but this is in my opinion irrelevant to the problem.

I've tried to debug and gain insight what happens, but had no success. ArquillianExtension.interceptTestTemplateMethod() seems to get called once on the client for each parameter, and then multiple times on the container which seems to indicate that the ParameterizedTestExtension is triggered twice.

In general it seems to be more correct if the parameter values are build on the container side, since in more sophisticated variants of @ParameterizedTest the provider code may rely on classes which exists on the container

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant