use of junit.framework.Test in project platform_frameworks_base by android.
the class TestRunner method run.
/*
This class determines if more suites are added to this class then adds all individual
test classes to a test suite for run
*/
public void run(String className) {
try {
mClassName = className;
Class clazz = mContext.getClassLoader().loadClass(className);
Method method = getChildrenMethod(clazz);
if (method != null) {
String[] children = getChildren(method);
run(children);
} else if (mRunnableClass.isAssignableFrom(clazz)) {
Runnable test = (Runnable) clazz.newInstance();
TestCase testcase = null;
if (test instanceof TestCase) {
testcase = (TestCase) test;
}
Throwable e = null;
boolean didSetup = false;
started(className);
try {
if (testcase != null) {
testcase.setUp(mContext);
didSetup = true;
}
if (mMode == PERFORMANCE) {
runInPerformanceMode(test, className, false, className);
} else if (mMode == PROFILING) {
//Need a way to mark a test to be run in profiling mode or not.
startProfiling();
test.run();
finishProfiling();
} else {
test.run();
}
} catch (Throwable ex) {
e = ex;
}
if (testcase != null && didSetup) {
try {
testcase.tearDown();
} catch (Throwable ex) {
e = ex;
}
}
finished(className);
if (e == null) {
passed(className);
} else {
failed(className, e);
}
} else if (mJUnitClass.isAssignableFrom(clazz)) {
Throwable e = null;
//Create a Junit Suite.
JunitTestSuite suite = new JunitTestSuite();
Method[] methods = getAllTestMethods(clazz);
for (Method m : methods) {
junit.framework.TestCase test = (junit.framework.TestCase) clazz.newInstance();
test.setName(m.getName());
if (test instanceof AndroidTestCase) {
AndroidTestCase testcase = (AndroidTestCase) test;
try {
testcase.setContext(mContext);
testcase.setTestContext(mContext);
} catch (Exception ex) {
Log.i("TestHarness", ex.toString());
}
}
suite.addTest(test);
}
if (mMode == PERFORMANCE) {
final int testCount = suite.testCount();
for (int j = 0; j < testCount; j++) {
Test test = suite.testAt(j);
started(test.toString());
try {
runInPerformanceMode(test, className, true, test.toString());
} catch (Throwable ex) {
e = ex;
}
finished(test.toString());
if (e == null) {
passed(test.toString());
} else {
failed(test.toString(), e);
}
}
} else if (mMode == PROFILING) {
//Need a way to mark a test to be run in profiling mode or not.
startProfiling();
junit.textui.TestRunner.run(suite);
finishProfiling();
} else {
junit.textui.TestRunner.run(suite);
}
} else {
System.out.println("Test wasn't Runnable and didn't have a" + " children method: " + className);
}
} catch (ClassNotFoundException e) {
Log.e("ClassNotFoundException for " + className, e.toString());
if (isJunitTest(className)) {
runSingleJunitTest(className);
} else {
missingTest(className, e);
}
} catch (InstantiationException e) {
System.out.println("InstantiationException for " + className);
missingTest(className, e);
} catch (IllegalAccessException e) {
System.out.println("IllegalAccessException for " + className);
missingTest(className, e);
}
}
use of junit.framework.Test in project platform_frameworks_base by android.
the class TestRunner method start.
/**
* Starts a test run. Analyzes the command line arguments and runs the given
* test suite.
*/
public TestResult start(String[] args) throws Exception {
String testCase = "";
String method = "";
boolean wait = false;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-wait"))
wait = true;
else if (args[i].equals("-c"))
testCase = extractClassName(args[++i]);
else if (args[i].equals("-m")) {
String arg = args[++i];
int lastIndex = arg.lastIndexOf('.');
testCase = arg.substring(0, lastIndex);
method = arg.substring(lastIndex + 1);
} else if (args[i].equals("-v"))
System.err.println("JUnit " + Version.id() + " by Kent Beck and Erich Gamma");
else
testCase = args[i];
}
if (testCase.equals(""))
throw new Exception("Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class");
try {
if (!method.equals(""))
return runSingleMethod(testCase, method, wait);
Test suite = getTest(testCase);
return doRun(suite, wait);
} catch (Exception e) {
throw new Exception("Could not create and run test suite: " + e);
}
}
use of junit.framework.Test in project platform_frameworks_base by android.
the class ListTestCaseNames method getTestNames.
/**
* Returns a list of test class and method names for each TestCase in suite.
*/
public static List<TestDescriptor> getTestNames(TestSuite suite) {
List<Test> tests = Collections.<Test>list(suite.tests());
ArrayList<TestDescriptor> testNames = new ArrayList<TestDescriptor>();
for (Test test : tests) {
if (test instanceof TestCase) {
String className = test.getClass().getName();
String testName = ((TestCase) test).getName();
testNames.add(new TestDescriptor(className, testName));
} else if (test instanceof TestSuite) {
testNames.addAll(getTestNames((TestSuite) test));
}
}
return testNames;
}
use of junit.framework.Test in project platform_frameworks_base by android.
the class InstrumentationTestRunnerTest method testMultipleTestClass.
public void testMultipleTestClass() throws Exception {
String classArg = PlaceHolderTest.class.getName() + "," + PlaceHolderTest2.class.getName();
mInstrumentationTestRunner.onCreate(createBundle(InstrumentationTestRunner.ARGUMENT_TEST_CLASS, classArg));
Test test = mStubAndroidTestRunner.getTest();
assertContentsInOrder(ListTestCaseNames.getTestNames((TestSuite) test), new TestDescriptor(PlaceHolderTest.class.getName(), "testPlaceHolder"), new TestDescriptor(PlaceHolderTest2.class.getName(), "testPlaceHolder2"));
}
use of junit.framework.Test in project platform_frameworks_base by android.
the class TestCaseUtilTest method testCreateTestForTestSuiteWithSuiteMethod.
public void testCreateTestForTestSuiteWithSuiteMethod() throws Exception {
Test test = TestCaseUtil.createTestSuite(TwoTestsInTestSuite.class);
assertEquals(2, test.countTestCases());
}
Aggregations