KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > tests > SuiteTest


1 package junit.tests;
2
3 import java.util.Vector JavaDoc;
4 import junit.framework.*;
5
6 /**
7  * A fixture for testing the "auto" test suite feature.
8  *
9  */

10 public class SuiteTest extends TestCase {
11     protected TestResult fResult;
12     public SuiteTest(String JavaDoc name) {
13         super(name);
14     }
15     protected void setUp() {
16         fResult= new TestResult();
17     }
18     public static Test suite() {
19         TestSuite suite= new TestSuite("Suite Tests");
20         // build the suite manually
21
suite.addTest(new SuiteTest("testNoTestCaseClass"));
22         suite.addTest(new SuiteTest("testNoTestCases"));
23         suite.addTest(new SuiteTest("testOneTestCase"));
24         suite.addTest(new SuiteTest("testNotPublicTestCase"));
25         suite.addTest(new SuiteTest("testNotVoidTestCase"));
26         suite.addTest(new SuiteTest("testNotExistingTestCase"));
27         suite.addTest(new SuiteTest("testInheritedTests"));
28         suite.addTest(new SuiteTest("testShadowedTests"));
29         suite.addTest(new SuiteTest("testAddTestSuite"));
30         
31         return suite;
32     }
33     public void testInheritedTests() {
34         TestSuite suite= new TestSuite(InheritedTestCase.class);
35         suite.run(fResult);
36         assertTrue(fResult.wasSuccessful());
37         assertEquals(2, fResult.runCount());
38     }
39     public void testNoTestCaseClass() {
40         Test t= new TestSuite(NoTestCaseClass.class);
41         t.run(fResult);
42         assertEquals(1, fResult.runCount()); // warning test
43
assertTrue(! fResult.wasSuccessful());
44     }
45     public void testNoTestCases() {
46         Test t= new TestSuite(NoTestCases.class);
47         t.run(fResult);
48         assertTrue(fResult.runCount() == 1); // warning test
49
assertTrue(fResult.failureCount() == 1);
50         assertTrue(! fResult.wasSuccessful());
51     }
52     public void testNotExistingTestCase() {
53         Test t= new SuiteTest("notExistingMethod");
54         t.run(fResult);
55         assertTrue(fResult.runCount() == 1);
56         assertTrue(fResult.failureCount() == 1);
57         assertTrue(fResult.errorCount() == 0);
58     }
59     public void testNotPublicTestCase() {
60         TestSuite suite= new TestSuite(NotPublicTestCase.class);
61         // 1 public test case + 1 warning for the non-public test case
62
assertEquals(2, suite.countTestCases());
63     }
64     public void testNotVoidTestCase() {
65         TestSuite suite= new TestSuite(NotVoidTestCase.class);
66         assertTrue(suite.countTestCases() == 1);
67     }
68     public void testOneTestCase() {
69         Test t= new TestSuite(OneTestCase.class);
70         t.run(fResult);
71         assertTrue(fResult.runCount() == 1);
72         assertTrue(fResult.failureCount() == 0);
73         assertTrue(fResult.errorCount() == 0);
74         assertTrue(fResult.wasSuccessful());
75     }
76     public void testShadowedTests() {
77         TestSuite suite= new TestSuite(OverrideTestCase.class);
78         suite.run(fResult);
79         assertEquals(1, fResult.runCount());
80     }
81     public void testAddTestSuite() {
82         TestSuite suite= new TestSuite();
83         suite.addTestSuite(OneTestCase.class);
84         suite.run(fResult);
85         assertEquals(1, fResult.runCount());
86     }
87 }
Popular Tags