Skip to content

Commit 8a17419

Browse files
committed
[Feature] add testSuite and let it run
1 parent 1bc48b1 commit 8a17419

File tree

14 files changed

+238
-52
lines changed

14 files changed

+238
-52
lines changed

students/812350401/src/main/java/com/coderising/myood/litejunit/liuxinv2/TestListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.coderising.myood.litejunit.liuxinv2;
22

33
/**
4-
* A Listener for test progress
4+
* A TestListener for test progress
55
*/
66
public interface TestListener {
77

students/812350401/src/main/java/com/coderising/myood/litejunit/v2/CalculatorTest.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

students/812350401/src/main/java/com/coderising/myood/litejunit/v2/ClientToTest.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
package com.coderising.myood.litejunit.v2;
22

33

4+
import com.coderising.myood.litejunit.v2.example_test.AllTest;
5+
46
/**
57
* Created by thomas_young on 21/8/2017.
68
*/
79
public class ClientToTest {
810

911
public static void main(String[] args) {
1012
TestResult tr = new TestResult();
11-
12-
// Test cs1 = new CalculatorTest("testAdd");
13-
// tryTest(cs1, tr);
14-
// Test cs2 = new CalculatorTest("testSubtract");
15-
// tryTest(cs2, tr);
16-
17-
System.out.println("---------------------------------");
18-
tr.clearResult();
19-
Test ts = new TestSuite("AllTest");
20-
// ((TestSuite)ts).addTest(new CalculatorTest("haha"));
21-
((TestSuite)ts).addTest(new TestSuite(CalculatorTest.class));
22-
tryTest(ts, tr);
23-
13+
Test testAll = AllTest.suite();
14+
tryTest(testAll, tr);
2415
}
2516

2617
private static void tryTest(Test test, TestResult tr) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.coderising.myood.litejunit.v2;
2+
3+
/**
4+
* Created by thomas_young on 17/9/2017.
5+
*/
6+
public interface TestListener {
7+
void addError(Test test, Throwable t);
8+
void addFailure(Test test, Throwable t);
9+
void startTest(Test test);
10+
void endTest(Test test);
11+
}

students/812350401/src/main/java/com/coderising/myood/litejunit/v2/TestSuite.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public int countTestCases() {
2424
return totalCount;
2525
}
2626

27+
public TestSuite(){
28+
}
2729
public TestSuite(String name) {
2830
this.name = name;
2931
}
@@ -125,4 +127,7 @@ private String exceptionToString(Throwable t) {
125127

126128
}
127129

130+
public void addTestSuite(Class testClass) {
131+
addTest(new TestSuite(testClass));
132+
}
128133
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.coderising.myood.litejunit.v2.example.a;
2+
3+
/**
4+
* Created by thomas_young on 17/9/2017.
5+
*/
6+
public class Calculator {
7+
public int add(int a,int b){
8+
return a + b;
9+
}
10+
public int minus(int a,int b){
11+
return a - b;
12+
}
13+
public int multiply(int a, int b ){
14+
return a * b;
15+
}
16+
public int divide(int a , int b )throws Exception
17+
{
18+
if(b == 0){
19+
throw new Exception("除数不能为零");
20+
}
21+
return a / b;
22+
}
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coderising.myood.litejunit.v2.example.b;
2+
3+
/**
4+
* Created by thomas_young on 17/9/2017.
5+
*/
6+
public class Byebye {
7+
public String Say(){
8+
return "Byebye!";
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coderising.myood.litejunit.v2.example.b;
2+
3+
/**
4+
* Created by thomas_young on 17/9/2017.
5+
*/
6+
public class HelloWorld {
7+
public String Say(){
8+
return "Hello,World!";
9+
}
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.coderising.myood.litejunit.v2.example_test;
2+
3+
import com.coderising.myood.litejunit.v2.Test;
4+
import com.coderising.myood.litejunit.v2.TestSuite;
5+
import com.coderising.myood.litejunit.v2.example_test.a.AAllTest;
6+
import com.coderising.myood.litejunit.v2.example_test.b.BAllTest;
7+
8+
/**
9+
* Created by thomas_young on 17/9/2017.
10+
*/
11+
public class AllTest {
12+
public static Test suite() {
13+
TestSuite suite = new TestSuite();
14+
suite.addTest(AAllTest.suite());
15+
suite.addTest(BAllTest.suite());
16+
return suite;
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.coderising.myood.litejunit.v2.example_test.a;
2+
3+
4+
import com.coderising.myood.litejunit.v2.Test;
5+
import com.coderising.myood.litejunit.v2.TestSuite;
6+
7+
/**
8+
* Created by thomas_young on 17/9/2017.
9+
*/
10+
public class AAllTest {
11+
public static Test suite() {
12+
TestSuite suite = new TestSuite();
13+
suite.addTestSuite(CalculatorTest.class);
14+
return suite;
15+
}
16+
}

0 commit comments

Comments
 (0)