KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > tests > framework > SuiteTest


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

9 public class SuiteTest extends TestCase {
10     protected TestResult fResult;
11     public SuiteTest(String JavaDoc name) {
12         super(name);
13     }
14     protected void setUp() {
15         fResult= new TestResult();
16     }
17     public static Test suite() {
18         TestSuite suite= new TestSuite("Suite Tests");
19         // build the suite manually, because some of the suites are testing
20
// the functionality that automatically builds suites
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