use of junit.framework.TestCase in project jena by apache.
the class AbstractTestPackage method addTest.
/**
* Adds a test to the test suite by looking for the standard test methods.
* These are
* methods that start with "test" and have no arguments.
*
* @param testClass
* @param constructorArgs
* @throws SecurityException
* @throws NoSuchMethodException
* @throws IllegalArgumentException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
private void addTest(final Class<? extends TestCase> testClass, final Object... constructorArgs) {
final Object[] args = new Object[constructorArgs.length + 1];
System.arraycopy(constructorArgs, 0, args, 0, constructorArgs.length);
final List<Class<?>> parameterTypes = new ArrayList<>();
for (final Object o : constructorArgs) {
if (o instanceof TestingModelFactory) {
parameterTypes.add(TestingModelFactory.class);
} else {
parameterTypes.add(o.getClass());
}
}
parameterTypes.add(String.class);
Constructor<TestCase> c;
try {
@SuppressWarnings("unchecked") Constructor<TestCase> cc = (Constructor<TestCase>) testClass.getConstructor(parameterTypes.toArray(new Class[parameterTypes.size()]));
c = cc;
} catch (final SecurityException | NoSuchMethodException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
for (final Method m : testClass.getMethods()) {
if (m.getParameterTypes().length == 0) {
if (m.getName().startsWith("test")) {
args[constructorArgs.length] = m.getName();
try {
addTest(c.newInstance(args));
} catch (final IllegalArgumentException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}
}
}
}
use of junit.framework.TestCase in project intellij-community by JetBrains.
the class ConfigurationsTest method testRunningAllInPackage.
public void testRunningAllInPackage() throws IOException, ExecutionException {
Module module1 = getModule1();
GlobalSearchScope module1AndLibraries = GlobalSearchScope.moduleWithLibrariesScope(module1);
PsiClass testCase = findClass(TestCase.class.getName(), module1AndLibraries);
PsiClass psiClass = findTestA(module1);
PsiClass psiClass2 = findTestA(getModule2());
PsiClass derivedTest = findClass(module1, "test1.DerivedTest");
PsiClass baseTestCase = findClass("junit.framework.ThirdPartyClass", module1AndLibraries);
PsiClass testB = findClass(getModule3(), "test1.TestB");
assertNotNull(testCase);
assertNotNull(derivedTest);
assertNotNull(psiClass);
assertTrue(psiClass.isInheritor(testCase, false));
assertEquals(baseTestCase, derivedTest.getSuperClass());
assertTrue(baseTestCase.isInheritor(testCase, true));
assertTrue(derivedTest.isInheritor(testCase, true));
PsiPackage psiPackage = JUnitUtil.getContainingPackage(psiClass);
JUnitConfiguration configuration = createConfiguration(psiPackage, module1);
JavaParameters parameters = checkCanRun(configuration);
List<String> lines = extractAllInPackageTests(parameters, psiPackage);
Assertion.compareUnordered(new Object[] { "", psiClass.getQualifiedName(), psiClass2.getQualifiedName(), derivedTest.getQualifiedName(), RT_INNER_TEST_NAME, testB.getQualifiedName() }, lines);
}
use of junit.framework.TestCase in project intellij-community by JetBrains.
the class BootstrapTests method suite.
public static Test suite() throws Throwable {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
String[] classes = System.getProperty("bootstrap.testcases").split(",");
TestSuite suite = new TestSuite();
for (String s : classes) {
final Class<?> aClass = Class.forName(s, true, cl);
if (TestCase.class.isAssignableFrom(aClass)) {
@SuppressWarnings("unchecked") final Class<? extends TestCase> testClass = (Class<? extends TestCase>) aClass;
suite.addTestSuite(testClass);
} else {
suite.addTest((Test) aClass.getMethod("suite").invoke(null));
}
}
return suite;
}
use of junit.framework.TestCase in project double-espresso by JakeWharton.
the class GoogleInstrumentationTestRunner method start.
@Override
public void start() {
List<TestCase> testCases = bridgeTestRunner.getAndroidTestRunner().getTestCases();
// Register a listener to update the current test description.
bridgeTestRunner.getAndroidTestRunner().addTestListener(new TestListener() {
@Override
public void startTest(Test test) {
runOnMainSync(new ActivityFinisher());
}
@Override
public void endTest(Test test) {
}
@Override
public void addFailure(Test test, AssertionFailedError ae) {
}
@Override
public void addError(Test test, Throwable t) {
}
});
super.start();
}
use of junit.framework.TestCase in project android_frameworks_base by crdroidandroid.
the class TestCaseCollector method addSingleTestMethod.
protected void addSingleTestMethod(Class<?> clazz, String method) {
if (!(mFilter.accept(clazz))) {
throw new RuntimeException("Test class must be derived from UiAutomatorTestCase");
}
try {
TestCase testCase = (TestCase) clazz.newInstance();
testCase.setName(method);
mTestCases.add(testCase);
} catch (InstantiationException e) {
mTestCases.add(error(clazz, "InstantiationException: could not instantiate " + "test class. Class: " + clazz.getName()));
} catch (IllegalAccessException e) {
mTestCases.add(error(clazz, "IllegalAccessException: could not instantiate " + "test class. Class: " + clazz.getName()));
}
}
Aggregations