private static Set<String> printTestLines(OutputValidator validator, String pattern) throws VerificationException { Set<String> log = new TreeSet<String>(validator.loadLogLines()); for (Iterator<String> it = log.iterator(); it.hasNext(); ) { String line = it.next(); if (!line.contains(pattern)) { it.remove(); } } return log; }
@Test public void testMethodsParallelWithSuite() throws VerificationException { OutputValidator validator = unpack().executeTest().verifyErrorFree(6); Set<String> testLines = printTestLines(validator, "test finished after duration="); assertThat(testLines.size(), is(2)); for (String testLine : testLines) { long duration = duration(testLine); long min = 250 * PERFORMANCE_TEST_MULTIPLICATION_FACTOR; long max = 750 * PERFORMANCE_TEST_MULTIPLICATION_FACTOR; assertTrue( format("duration %d should be between %d and %d ms", duration, min, max), duration > min && duration < max); } Set<String> suiteLines = printTestLines(validator, "suite finished after duration="); assertThat(suiteLines.size(), is(1)); long duration = duration(suiteLines.iterator().next()); long min = 750 * PERFORMANCE_TEST_MULTIPLICATION_FACTOR; long max = 1250 * PERFORMANCE_TEST_MULTIPLICATION_FACTOR; assertTrue( format("duration %d should be between %d and %d ms", duration, min, max), duration > min && duration < max); String delayMin = lowerScaleFormatter.format(0.98 * PERFORMANCE_TEST_MULTIPLICATION_FACTOR * 0.5); String delayMax = noFractionalDigitsFormatter.format(PERFORMANCE_TEST_MULTIPLICATION_FACTOR * 0.5) + "."; for (String line : validator.loadLogLines()) { if (line.startsWith("Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed:")) { assertThat( line, anyOf( // 1.9xx to 2.xxx can vary depending on CI jobs containsString("Time elapsed: " + delayMin), containsString("Time elapsed: " + delayMax))); assertThat( line, anyOf( endsWith(" s - in surefire747.SuiteTest1"), endsWith(" s - in surefire747.SuiteTest2"))); } } }