use of junit.framework.TestCase in project junit4 by junit-team.
the class ExtensionTest method testRunningErrorInTestSetup.
public void testRunningErrorInTestSetup() {
TestCase test = new TestCase("failure") {
@Override
public void runTest() {
fail();
}
};
TestSetup wrapper = new TestSetup(test);
TestResult result = new TestResult();
wrapper.run(result);
assertTrue(!result.wasSuccessful());
}
use of junit.framework.TestCase in project platform_frameworks_base by android.
the class AndroidTestRunner method runTest.
public void runTest(TestResult testResult) {
mTestResult = testResult;
for (TestListener testListener : mTestListeners) {
mTestResult.addListener(testListener);
}
Context testContext = mInstrumentation == null ? mContext : mInstrumentation.getContext();
for (TestCase testCase : mTestCases) {
setContextIfAndroidTestCase(testCase, mContext, testContext);
setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation);
setPerformanceWriterIfPerformanceCollectorTestCase(testCase, mPerfWriter);
testCase.run(mTestResult);
}
}
use of junit.framework.TestCase in project platform_frameworks_base by android.
the class TestMethod method instantiateTest.
@SuppressWarnings("unchecked")
private TestCase instantiateTest(Class testCaseClass, String testName) throws InvocationTargetException, IllegalAccessException, InstantiationException {
Constructor[] constructors = testCaseClass.getConstructors();
if (constructors.length == 0) {
return instantiateTest(testCaseClass.getSuperclass(), testName);
} else {
for (Constructor constructor : constructors) {
Class[] params = constructor.getParameterTypes();
if (noargsConstructor(params)) {
TestCase test = ((Constructor<? extends TestCase>) constructor).newInstance();
// JUnit will run just the one test if you call
// {@link TestCase#setName(String)}
test.setName(testName);
return test;
} else if (singleStringConstructor(params)) {
return ((Constructor<? extends TestCase>) constructor).newInstance(testName);
}
}
}
throw new RuntimeException("Unable to locate a constructor for " + testCaseClass.getName());
}
use of junit.framework.TestCase in project platform_frameworks_base by android.
the class TestSuiteBuilder method build.
/**
* Call this method once you've configured your builder as desired.
*
* @return The suite containing the requested tests.
*/
public final TestSuite build() {
rootSuite = new TestSuite(getSuiteName());
// Keep track of current class so we know when to create a new sub-suite.
currentClassname = null;
try {
for (TestMethod test : testGrouping.getTests()) {
if (satisfiesAllPredicates(test)) {
addTest(test);
}
}
if (testCases.size() > 0) {
for (TestCase testCase : testCases) {
if (satisfiesAllPredicates(new TestMethod(testCase))) {
addTest(testCase);
}
}
}
} catch (Exception exception) {
Log.i("TestSuiteBuilder", "Failed to create test.", exception);
TestSuite suite = new TestSuite(getSuiteName());
suite.addTest(new FailedToCreateTests(exception));
return suite;
}
return rootSuite;
}
use of junit.framework.TestCase in project platform_frameworks_base by android.
the class AndroidTestRunnerTest method testRunTestWithAndroidTestCaseInSuite.
public void testRunTestWithAndroidTestCaseInSuite() throws Exception {
mAndroidTestRunner.setTestClassName(OneAndroidTestTestCase.class.getName(), null);
TestListenerStub testListenerStub = new TestListenerStub();
mAndroidTestRunner.addTestListener(testListenerStub);
mAndroidTestRunner.runTest();
assertTrue(testListenerStub.saw("testOneAndroid"));
List<TestCase> testCases = mAndroidTestRunner.getTestCases();
for (TestCase testCase : testCases) {
assertSame(mStubContext, ((AndroidTestCase) testCase).getContext());
}
}
Aggregations