-
Notifications
You must be signed in to change notification settings - Fork 202
[#771] Fix @RepeatedTest running N*N times in container mode #846
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,10 +21,12 @@ | |
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| import org.jboss.arquillian.junit5.extension.RunModeEvent; | ||
| import org.jboss.arquillian.test.spi.LifecycleMethodExecutor; | ||
| import org.jboss.arquillian.test.spi.TestMethodExecutor; | ||
| import org.jboss.arquillian.test.spi.TestResult; | ||
| import org.jboss.arquillian.test.spi.TestRunnerAdaptor; | ||
| import org.jboss.arquillian.test.spi.event.suite.TestLifecycleEvent; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.platform.launcher.listeners.TestExecutionSummary; | ||
|
|
@@ -44,6 +46,13 @@ protected void executeAllLifeCycles(TestRunnerAdaptor adaptor) throws Exception | |
| doAnswer(new ExecuteLifecycle()).when(adaptor).before(any(Object.class), any(Method.class), any(LifecycleMethodExecutor.class)); | ||
| doAnswer(new ExecuteLifecycle()).when(adaptor).after(any(Object.class), any(Method.class), any(LifecycleMethodExecutor.class)); | ||
| doAnswer(new TestExecuteLifecycle()).when(adaptor).test(any(TestMethodExecutor.class)); | ||
| doAnswer(invocation -> { | ||
| TestLifecycleEvent event = invocation.getArgument(0); | ||
| if (event instanceof RunModeEvent) { | ||
| ((RunModeEvent) event).setRunAsClient(false); | ||
| } | ||
| return null; | ||
| }).when(adaptor).fireCustomLifecycle(any(TestLifecycleEvent.class)); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -55,12 +64,29 @@ public void shouldExecuteRepeatedTestExactlyThreeTimes() throws Exception { | |
| // when | ||
| TestExecutionSummary result = run(adaptor, ClassWithArquillianExtensionAndRepeatedTest.class); | ||
|
|
||
| // then — @RepeatedTest(3) must run exactly 3 times, not 9 | ||
| Assertions.assertEquals(3, result.getTestsSucceededCount()); | ||
| // then — @RepeatedTest(3) must invoke SPI lifecycle exactly 3 times, not 9 | ||
| Assertions.assertEquals(0, result.getTestsFailedCount()); | ||
| Assertions.assertEquals(0, result.getTestsSkippedCount()); | ||
| assertCycle(1, Cycle.BEFORE_CLASS, Cycle.AFTER_CLASS); | ||
| assertCycle(3, Cycle.BEFORE, Cycle.TEST, Cycle.AFTER); | ||
| verify(adaptor, times(1)).beforeClass(any(Class.class), any(LifecycleMethodExecutor.class)); | ||
| verify(adaptor, times(1)).afterClass(any(Class.class), any(LifecycleMethodExecutor.class)); | ||
| verify(adaptor, times(3)).before(any(Object.class), any(Method.class), any(LifecycleMethodExecutor.class)); | ||
| verify(adaptor, times(3)).after(any(Object.class), any(Method.class), any(LifecycleMethodExecutor.class)); | ||
| verify(adaptor, times(1)).test(any(TestMethodExecutor.class)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would the test only be executed once? Maybe I don't understand this test framework though.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jamezp Good question, my understanding is that in container mode - which was the reason why the test was passing before as it was in the client mode - adaptor.test() sends the test to the container via the ARQ protocol. The container executes the test method remotely - once. So what is the alternative - the client side would call adaptor.test() for each of the 3 repetitions, and the container would execute just the method body once per call and NOT expand to the @RepeatedTest template. The problem we have now is that both are expanding so we do get N*N. |
||
| } | ||
|
|
||
| @Test | ||
| public void shouldReportFailuresForAllRepetitions() throws Exception { | ||
| // given | ||
| TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); | ||
| executeAllLifeCycles(adaptor); | ||
| doAnswer(invocation -> TestResult.failed(new AssertionError("expected failure"))) | ||
| .when(adaptor).test(any(TestMethodExecutor.class)); | ||
|
|
||
| // when | ||
| TestExecutionSummary result = run(adaptor, ClassWithArquillianExtensionAndRepeatedTest.class); | ||
|
|
||
| // then — all 3 repetitions must report as failed | ||
| Assertions.assertEquals(3, result.getTestsFailedCount()); | ||
| verify(adaptor, times(1)).test(any(TestMethodExecutor.class)); | ||
| } | ||
|
|
||
| public static class TestExecuteLifecycle extends ExecuteLifecycle { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.