| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.test.suitebuilder; |
| 18 |
|
| 19 |
import junit.framework.Test; |
| 20 |
import junit.framework.TestCase; |
| 21 |
import junit.framework.TestSuite; |
| 22 |
|
| 23 |
import java.util.ArrayList; |
| 24 |
import java.util.Collections; |
| 25 |
import java.util.List; |
| 26 |
|
| 27 |
public class ListTestCaseNames { |
| 28 |
public static List<String> getTestCaseNames(TestSuite suite) { |
| 29 |
|
| 30 |
List<Test> tests = Collections.<Test>list(suite.tests()); |
| 31 |
ArrayList<String> testCaseNames = new ArrayList<String>(); |
| 32 |
for (Test test : tests) { |
| 33 |
if (test instanceof TestCase) { |
| 34 |
testCaseNames.add(((TestCase) test).getName()); |
| 35 |
} else if (test instanceof TestSuite) { |
| 36 |
testCaseNames.addAll(getTestCaseNames((TestSuite) test)); |
| 37 |
} |
| 38 |
} |
| 39 |
return testCaseNames; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public static List<TestDescriptor> getTestNames(TestSuite suite) { |
| 46 |
List<Test> tests = Collections.<Test>list(suite.tests()); |
| 47 |
ArrayList<TestDescriptor> testNames = new ArrayList<TestDescriptor>(); |
| 48 |
for (Test test : tests) { |
| 49 |
if (test instanceof TestCase) { |
| 50 |
String className = test.getClass().getName(); |
| 51 |
String testName = ((TestCase) test).getName(); |
| 52 |
testNames.add(new TestDescriptor(className, testName)); |
| 53 |
} else if (test instanceof TestSuite) { |
| 54 |
testNames.addAll(getTestNames((TestSuite) test)); |
| 55 |
} |
| 56 |
} |
| 57 |
return testNames; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public static class TestDescriptor { |
| 64 |
private String mClassName; |
| 65 |
private String mTestName; |
| 66 |
|
| 67 |
public TestDescriptor(String className, String testName) { |
| 68 |
mClassName = className; |
| 69 |
mTestName = testName; |
| 70 |
} |
| 71 |
|
| 72 |
public String getClassName() { |
| 73 |
return mClassName; |
| 74 |
} |
| 75 |
|
| 76 |
public String getTestName() { |
| 77 |
return mTestName; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
@Override |
| 84 |
public boolean equals(Object otherObj) { |
| 85 |
if (otherObj instanceof TestDescriptor) { |
| 86 |
TestDescriptor otherDesc = (TestDescriptor)otherObj; |
| 87 |
return otherDesc.getClassName().equals(this.getClassName()) && |
| 88 |
otherDesc.getTestName().equals(this.getTestName()); |
| 89 |
|
| 90 |
} |
| 91 |
return false; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
@Override |
| 98 |
public String toString() { |
| 99 |
return getClassName() + "#" + getTestName(); |
| 100 |
} |
| 101 |
} |
| 102 |
} |