| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.test; |
| 18 | |
| 19 | import junit.framework.Test; |
| 20 | import junit.framework.TestCase; |
| 21 | import junit.framework.TestSuite; |
| 22 | |
| 23 | import java.util.List; |
| 24 | |
| 25 | public 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 Duffin | 2a637cf | 2017-06-22 12:52:18 +0100 | [diff] [blame^] | 32 | assertEquals(0, testCaseNames.size()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | } |
| 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 | } |