Reputation: 37034
I have following test:
@RunWith(Parameterized.class)
@SpringBootTest
@ContextConfiguration(classes = MyConfiguration.class)
public class OrderPlacementCancelTest {
public static final int REQUESTS_PER_USER = 100;
@Parameterized.Parameter(0)
public String apiKey;
@Parameterized.Parameter(1)
public String secretKey;
@Parameterized.Parameter(2)
public String passPhrase;
@Parameterized.Parameter(3)
public String destination;
@Parameterized.Parameter(4)
public int index;
@Test
public void placeLimitAndThenCancel() throws InterruptedException, FieldNotFound, SessionNotFound, DoNotSend, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
for (int i = 0; i < REQUESTS_PER_USER; i++) {
System.out.println("ITERATION_" + i);
}
}
@Parameterized.Parameters()
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"1", "1", "1", "1", 1},
{"1", "1", "1", "1", 1},
{"1", "1", "1", "1", 1},
{"1", "1", "1", "1", 1},
{"1", "1", "1", "1", 1},
});
}
}
and I have following runner:
public class ParallelRunner {
@Test
public void test() {
Class[] cls = {OrderPlacementCancelTest.class};
JUnitCore.runClasses(new ParallelComputer(false, true), cls);
}
}
I start my runner and after tests have finished I review logs.
I can't explain result:
I see that
ITERATION_0
- 5 matches
...
ITERATION_5
- 55 matches
...
ITERATION_9
- 55 matches
...
ITERATION_10
- 5 matches
...
ITERATION_50
- 5 matches
...
ITERATION_70
- 5 matches
...
ITERATION_98
- 5 matches
ITERATION_99
- 5 matches
Expected result 100 matches for each iteration.
Can you please explain this behaviour and way to fix it?
Upvotes: 0
Views: 37
Reputation: 7620
Your result is correct (I think).
Since you have ParallelComputer
run methods in parallel, and your tests are parametrised, the number of test methods generated is the number of elements in the first dimension of the array. In your case this number is 5, and this is what you see.
The fact that you find ITERATION_5
55 times is because this term matches
ITERATION_5
, ITERATION_50
, ITERATION_51
, ... ,ITERATION_59
as in 11 matches per one run multiplied by 5 runs equals 55.
You will see this effect for all single digit iteration numbers, and your search for ITERATION_9
confirms it.
Try text searching for ITERATION_
term to find 500 matches or searching for term 'ITERATION_5 '
(white space after 5) should give you 5 matches.
Upvotes: 1