mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit tests: ensure duration is skipped in tests
This commit is contained in:
+17
-18
@@ -202,12 +202,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
|
||||
|
||||
private static void doTest(Description root, List<Description> tests, String expectedTree, String expectedStart) throws Exception {
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
final JUnit4TestListener sender = new JUnit4TestListener(new PrintStream(new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
buf.append(new String(new byte[]{(byte)b}));
|
||||
}
|
||||
}));
|
||||
final JUnit4TestListener sender = createListener(buf);
|
||||
sender.sendTree(root);
|
||||
|
||||
Assert.assertEquals("output: " + buf, expectedTree, StringUtil.convertLineSeparators(buf.toString()));
|
||||
@@ -249,12 +244,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
|
||||
}
|
||||
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
final JUnit4TestListener sender = new JUnit4TestListener(new PrintStream(new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
buf.append(new String(new byte[]{(byte)b}));
|
||||
}
|
||||
}));
|
||||
final JUnit4TestListener sender = createListener(buf);
|
||||
|
||||
sender.testRunStarted(root);
|
||||
for (Description test : tests) {
|
||||
@@ -276,6 +266,20 @@ public class JUnitTreeByDescriptionHierarchyTest {
|
||||
"##teamcity[testSuiteFinished name='TestB']\n", StringUtil.convertLineSeparators(buf.toString()));
|
||||
}
|
||||
|
||||
private static JUnit4TestListener createListener(final StringBuffer buf) {
|
||||
return new JUnit4TestListener(new PrintStream(new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
buf.append(new String(new byte[]{(byte)b}));
|
||||
}
|
||||
})) {
|
||||
@Override
|
||||
protected long currentTime() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizedTestsUpsideDown() throws Exception {
|
||||
final Description aTestClass = Description.createSuiteDescription("ATest");
|
||||
@@ -372,12 +376,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
|
||||
|
||||
private static void doTest(Description description, String expected) {
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
new JUnit4TestListener(new PrintStream(new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
buf.append(new String(new byte[]{(byte)b}));
|
||||
}
|
||||
})).sendTree(description);
|
||||
createListener(buf).sendTree(description);
|
||||
|
||||
Assert.assertEquals("output: " + buf, expected, StringUtil.convertLineSeparators(buf.toString()));
|
||||
}
|
||||
|
||||
@@ -121,11 +121,15 @@ public class JUnit4TestListener extends RunListener {
|
||||
|
||||
myPrintStream.println("##teamcity[testStarted name=\'" + escapeName(methodName) + "\' " +
|
||||
getTestMethodLocation(methodName, classFQN) + "]");
|
||||
myCurrentTestStart = System.currentTimeMillis();
|
||||
myCurrentTestStart = currentTime();
|
||||
}
|
||||
|
||||
protected long currentTime() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void testFinished(Description description) throws Exception {
|
||||
final long duration = System.currentTimeMillis() - myCurrentTestStart;
|
||||
final long duration = currentTime() - myCurrentTestStart;
|
||||
myPrintStream.println("\n##teamcity[testFinished name=\'" + escapeName(JUnit4ReflectionUtil.getMethodName(description)) +
|
||||
(duration > 0 ? "\' duration=\'" + Long.toString(duration) : "") + "\']");
|
||||
}
|
||||
@@ -133,7 +137,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
public void testFailure(Failure failure) throws Exception {
|
||||
final Map attrs = new HashMap();
|
||||
attrs.put("name", JUnit4ReflectionUtil.getMethodName(failure.getDescription()));
|
||||
final long duration = System.currentTimeMillis() - myCurrentTestStart;
|
||||
final long duration = currentTime() - myCurrentTestStart;
|
||||
if (duration > 0) {
|
||||
attrs.put("duration", Long.toString(duration));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user