File tree 3 files changed +42
-5
lines changed
maven3-junit4-runner/src/main/java/io/tech/runner/junit
3 files changed +42
-5
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
- echo " TECHIO> terminal"
2
+ # echo "TECHIO> terminal"
3
3
# Can be invoked as:
4
4
# xxx.sh SOURCE_DIR TestClass
5
5
# xxx.sh SOURCE_DIR TestClass#testMethod
@@ -37,7 +37,5 @@ compilationExitCode=$?
37
37
if [ $compilationExitCode -eq 0 ]; then
38
38
java -cp " ${WORKSPACE_DIR} :$classpath :/opt/techio/junit-runner/junit-runner.jar" io.tech.runner.junit.JUnitTestListRunner $1
39
39
else
40
- sleep 1000
41
40
exit $compilationExitCode
42
41
fi
43
- sleep 1000
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ class JUnitTest {
12
12
* This captures ClassName or ClassName#methodName (e.g. TestBoid#testUnique)
13
13
*/
14
14
private static final Pattern COMMAND_PATTERN = Pattern .compile ("(?<class>[^#]+)(?:#(?<method>[^#]+))?" );
15
+
16
+ private String stackStop = null ;
15
17
16
18
int run (String testcaseSpecification ) {
17
19
Request request = findRequest (testcaseSpecification );
@@ -31,9 +33,11 @@ Request findRequest(String testcaseSpecification) {
31
33
String method = matcher .group ("method" );
32
34
if (method != null ) {
33
35
request = Request .method (clazz , method );
36
+ stackStop = clazz .getName () + "." + method ;
34
37
}
35
38
else {
36
39
request = Request .aClass (clazz );
40
+ stackStop = clazz .getName ();
37
41
}
38
42
}
39
43
catch (ClassNotFoundException ignored ) {}
@@ -43,7 +47,7 @@ Request findRequest(String testcaseSpecification) {
43
47
44
48
private int runTestCase (Request request ) {
45
49
JUnitCore jUnitCore = new JUnitCore ();
46
- jUnitCore .addListener (new TestResultFormatter ());
50
+ jUnitCore .addListener (new TestResultFormatter (stackStop ));
47
51
return jUnitCore .run (request ).wasSuccessful () ? 0 : 1 ;
48
52
}
49
53
}
Original file line number Diff line number Diff line change 1
1
package io .tech .runner .junit ;
2
2
3
+ import java .io .BufferedOutputStream ;
4
+ import java .io .PrintStream ;
5
+
3
6
import org .junit .runner .notification .Failure ;
4
7
import org .junit .runner .notification .RunListener ;
5
8
6
9
public class TestResultFormatter extends RunListener {
10
+
11
+ private String stackStop ;
12
+
13
+ public TestResultFormatter (String stackStop ) {
14
+ this .stackStop = stackStop ;
15
+ }
16
+
7
17
@ Override
8
18
public void testFailure (Failure failure ) {
9
- failure .getException ().printStackTrace ();
19
+
20
+ String [] stackLines = failure .getTrace ().split ("\n " );
21
+
22
+ int excludeStart = stackLines .length ;
23
+ int excludeStop = stackLines .length ;
24
+
25
+ for (int i = 0 , il = stackLines .length ; i < il ; i ++) {
26
+ if (stackLines [i ].contains (stackStop )) {
27
+ excludeStart = i + 1 ;
28
+ break ;
29
+ }
30
+ }
31
+ for (int i = excludeStart , il = stackLines .length ; i < il ; i ++) {
32
+ if (stackLines [i ].contains ("Caused by" )) {
33
+ excludeStop = i - 1 ;
34
+ break ;
35
+ }
36
+ }
37
+
38
+ PrintStream ps = new PrintStream (new BufferedOutputStream (System .err ));
39
+
40
+ for (int i = 0 , il = stackLines .length ; i < il ; i ++) {
41
+ if (i < excludeStart || i > excludeStop ) {
42
+ ps .print (stackLines [i ]);
43
+ }
44
+ }
10
45
}
11
46
}
You can’t perform that action at this time.
0 commit comments