diff options
author | 2017-06-22 13:29:26 +0100 | |
---|---|---|
committer | 2017-06-22 15:21:32 +0100 | |
commit | bd96f408085701fe04fb46acdd3a101cfdebe064 (patch) | |
tree | 211204ffbd93dbe997cbde7f1c78409ff902ae4d /test-runner/tests | |
parent | 2a637cf9b0f2c2ebaf573a1f478e31dc1e6a8354 (diff) |
Clean up TestCaseUtil
Part of the work of removing JUnit and dependent android.test classes
from the Android API involves providing a static library that developers
can include in their test applications to ease migration. That library
will be built directly from the source (as opposed to android.jar which
is built from stubs) and so developers will be able to see classes and
methods that are not present in the stubs. This change is one of a
number of similar changes that cleanup the existing non-API code in
order to minimize the additional methods and classes exposed externally.
The basic approach is to remove unused classes and methods, use least
visible access modifier possible and generally minimize the amount of
publicly visible code.
TestCaseUtil.getTestCaseNames() is only used by tests but its tests did
provide some coverage of the getTests() method so remove the method and
the tests the method was simply moved into TestCaseUtilTest and the
tests renamed to make it clearer that they are testing
TestCaseUtil.getTests().
Similarly, TestCaseUtil.createTestSuite() was only used by tests but its
tests did provide some coverage of the invokeSuiteMethodIfPossible()
method so the tests were modified and renamed to preserve that coverage.
TestCaseUtil.getTestAtIndex() was completely unused so was just removed.
Bug: 30188076
Test: make checkbuild and ran FrameworkTestRunnerTests
Change-Id: I62bbdbab428d7560f0c7df11f313fe60cfd31d13
Diffstat (limited to 'test-runner/tests')
-rw-r--r-- | test-runner/tests/src/android/test/TestCaseUtilTest.java | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/test-runner/tests/src/android/test/TestCaseUtilTest.java b/test-runner/tests/src/android/test/TestCaseUtilTest.java index 9d12eafcd34f..6d424b08dfb1 100644 --- a/test-runner/tests/src/android/test/TestCaseUtilTest.java +++ b/test-runner/tests/src/android/test/TestCaseUtilTest.java @@ -16,6 +16,8 @@ package android.test; +import java.util.ArrayList; +import java.util.HashSet; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -24,38 +26,50 @@ import java.util.List; public class TestCaseUtilTest extends TestCase { - public void testGetTestCaseNamesForTestSuiteWithSuiteMethod() throws Exception { + @SuppressWarnings("unchecked") + private static List<String> getTestCaseNames(Test test) { + List<Test> tests = (List<Test>) TestCaseUtil.getTests(test, false); + List<String> testCaseNames = new ArrayList<>(); + for (Test aTest : tests) { + testCaseNames.add(TestCaseUtil.getTestName(aTest)); + } + return testCaseNames; + } + + public void testGetTests_ForTestSuiteWithSuiteMethod() throws Exception { TestSuite testSuite = new TwoTestsInTestSuite(); - List<String> testCaseNames = TestCaseUtil.getTestCaseNames(testSuite, false); + List<String> testCaseNames = getTestCaseNames(testSuite); assertEquals(0, testCaseNames.size()); } - public void testGetTestCaseNamesForTestCaseWithSuiteMethod() throws Exception { + public void testGetTests_ForTestCaseWithSuiteMethod() throws Exception { TestCase testCase = new OneTestTestCaseWithSuite(); - List<String> testCaseNames = TestCaseUtil.getTestCaseNames(testCase, false); + List<String> testCaseNames = getTestCaseNames(testCase); assertEquals(1, testCaseNames.size()); assertTrue(testCaseNames.get(0).endsWith("testOne")); } - public void testCreateTestForTestCase() throws Exception { - Test test = TestCaseUtil.createTestSuite(OneTestTestCase.class); - assertEquals(1, test.countTestCases()); + public void testInvokeSuiteMethodIfPossible_ForTestCase() throws Exception { + Test test = TestCaseUtil.invokeSuiteMethodIfPossible(OneTestTestCase.class, new HashSet<>()); + assertNull(test); } - - public void testCreateTestForTestSuiteWithSuiteMethod() throws Exception { - Test test = TestCaseUtil.createTestSuite(TwoTestsInTestSuite.class); + + public void testInvokeSuiteMethodIfPossible_ForTestSuiteWithSuiteMethod() throws Exception { + Test test = TestCaseUtil.invokeSuiteMethodIfPossible(TwoTestsInTestSuite.class, new HashSet<>()); + assertNotNull(test); assertEquals(2, test.countTestCases()); } - public void testCreateTestForTestCaseWithSuiteMethod() throws Exception { - Test test = TestCaseUtil.createTestSuite(OneTestTestCaseWithSuite.class); + public void testInvokeSuiteMethodIfPossible_ForTestCaseWithSuiteMethod() throws Exception { + Test test = TestCaseUtil.invokeSuiteMethodIfPossible(OneTestTestCaseWithSuite.class, new HashSet<>()); + assertNotNull(test); assertEquals(1, test.countTestCases()); } - + public void testReturnEmptyStringForTestSuiteWithNoName() throws Exception { assertEquals("", TestCaseUtil.getTestName(new TestSuite())); } |