blob: 9d12eafcd34f4074b79b93a9ff98dd33f3257f77 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.test;
18
19import junit.framework.Test;
20import junit.framework.TestCase;
21import junit.framework.TestSuite;
22
23import java.util.List;
24
25public class TestCaseUtilTest extends TestCase {
26
27 public void testGetTestCaseNamesForTestSuiteWithSuiteMethod() throws Exception {
28 TestSuite testSuite = new TwoTestsInTestSuite();
29
30 List<String> testCaseNames = TestCaseUtil.getTestCaseNames(testSuite, false);
31
Paul Duffin2a637cf2017-06-22 12:52:18 +010032 assertEquals(0, testCaseNames.size());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033 }
34
35 public void testGetTestCaseNamesForTestCaseWithSuiteMethod() throws Exception {
36 TestCase testCase = new OneTestTestCaseWithSuite();
37
38 List<String> testCaseNames = TestCaseUtil.getTestCaseNames(testCase, false);
39
40 assertEquals(1, testCaseNames.size());
41 assertTrue(testCaseNames.get(0).endsWith("testOne"));
42 }
43
44 public void testCreateTestForTestCase() throws Exception {
45 Test test = TestCaseUtil.createTestSuite(OneTestTestCase.class);
46 assertEquals(1, test.countTestCases());
47 }
48
49 public void testCreateTestForTestSuiteWithSuiteMethod() throws Exception {
50 Test test = TestCaseUtil.createTestSuite(TwoTestsInTestSuite.class);
51 assertEquals(2, test.countTestCases());
52 }
53
54 public void testCreateTestForTestCaseWithSuiteMethod() throws Exception {
55 Test test = TestCaseUtil.createTestSuite(OneTestTestCaseWithSuite.class);
56 assertEquals(1, test.countTestCases());
57 }
58
59 public void testReturnEmptyStringForTestSuiteWithNoName() throws Exception {
60 assertEquals("", TestCaseUtil.getTestName(new TestSuite()));
61 }
62
63 public static class OneTestTestCase extends TestCase {
64 public void testOne() throws Exception {
65 }
66 }
67
68 public static class OneTestTestCaseWithSuite extends TestCase {
69 public static Test suite() {
70 TestCase testCase = new OneTestTestCase();
71 testCase.setName("testOne");
72 return testCase;
73 }
74
75 public void testOne() throws Exception {
76 }
77
78 public void testTwo() throws Exception {
79 }
80 }
81
82 public static class OneTestTestSuite {
83 public static Test suite() {
84 TestSuite suite = new TestSuite(OneTestTestSuite.class.getName());
85 suite.addTestSuite(OneTestTestCase.class);
86 return suite;
87 }
88 }
89
90 public static class TwoTestsInTestSuite extends TestSuite {
91 public static Test suite() {
92 TestSuite suite = new TestSuite(TwoTestsInTestSuite.class.getName());
93 suite.addTestSuite(OneTestTestCase.class);
94 suite.addTest(OneTestTestSuite.suite());
95 return suite;
96 }
97 }
98}