File tree Expand file tree Collapse file tree 5 files changed +112
-3
lines changed
students/1299310140/src/com/coderising/junit Expand file tree Collapse file tree 5 files changed +112
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
public class AllTest {
4
4
5
+ // public static Test suite(){
6
+ // TestSuite suite = new TestSuite("All Test");
7
+ // suite.addTestSuite(CalculatorTest.class);
8
+ // suite.addTestSuite(CalculatorTest.class);
9
+ // return suite;
10
+ // }
11
+
5
12
public static Test suite (){
6
13
TestSuite suite = new TestSuite ("All Test" );
7
- suite .addTestSuite (CalculatorTest .class );
8
- suite .addTestSuite (CalculatorTest .class );
9
- return suite ;
14
+ suite .addTest (CalculatorSuite .suite ());
15
+ // suite.addTestSuite(CalculatorTest.class);
16
+ suite .addTest (new RepeatedTest (new TestSuite (CalculatorTest .class ),3 ));
17
+ return new OverallTestSetup (suite );
18
+ }
19
+
20
+ static class OverallTestSetup extends TestSetUp {
21
+
22
+ public OverallTestSetup (Test test ) {
23
+ super (test );
24
+ }
25
+
26
+ @ Override
27
+ public void setUp (){
28
+ System .out .println ("this is overall testsetup" );
29
+ }
30
+
31
+ @ Override
32
+ public void tearDown (){
33
+ System .out .println ("this is overall testteardown" );
34
+ }
10
35
}
11
36
}
Original file line number Diff line number Diff line change
1
+ package com .coderising .junit ;
2
+
3
+ public interface Protectable {
4
+ public void protect () throws Throwable ;
5
+ }
Original file line number Diff line number Diff line change
1
+ package com .coderising .junit ;
2
+
3
+ public class RepeatedTest extends TestDecorator {
4
+
5
+ private int fTimesRepeat ;
6
+
7
+ public RepeatedTest (Test test ,int repeat ) {
8
+ super (test );
9
+ if (repeat < 0 )
10
+ throw new IllegalArgumentException ("repeation count must be > 0" );
11
+ this .fTimesRepeat = repeat ;
12
+ }
13
+
14
+ public int countTestCases (){
15
+ return super .countTestCases () * fTimesRepeat ;
16
+ }
17
+
18
+ public void run (TestResult testResult ){
19
+ for (int i = 0 ;i < fTimesRepeat ;i ++){
20
+ super .run (testResult );
21
+ }
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ package com .coderising .junit ;
2
+
3
+ public class TestDecorator implements Test {
4
+
5
+ protected Test test ;
6
+
7
+ public TestDecorator (Test test ){
8
+ this .test = test ;
9
+ }
10
+
11
+ @ Override
12
+ public void run (TestResult tr ) {
13
+ basicRun (tr );
14
+ }
15
+
16
+ public void basicRun (TestResult tr ) {
17
+ this .test .run (tr );
18
+ }
19
+
20
+ @ Override
21
+ public int countTestCases () {
22
+
23
+ return test .countTestCases ();
24
+ }
25
+
26
+ }
Original file line number Diff line number Diff line change
1
+ package com .coderising .junit ;
2
+
3
+ public class TestSetUp extends TestDecorator {
4
+
5
+ public TestSetUp (Test test ) {
6
+ super (test );
7
+ }
8
+
9
+ public void run (final TestResult testResult ){
10
+ Protectable p = new Protectable () {
11
+ @ Override
12
+ public void protect () throws Throwable {
13
+ setUp ();
14
+ basicRun (testResult );
15
+ tearDown ();
16
+ }
17
+ };
18
+
19
+ testResult .runProtected (this , p );
20
+ }
21
+
22
+ protected void tearDown () {
23
+
24
+ }
25
+
26
+ protected void setUp () {
27
+
28
+ }
29
+
30
+ }
You can’t perform that action at this time.
0 commit comments