Search in sources :

Example 51 with TestCase

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);
                }
            }
        }
    }
}
Also used : Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) TestCase(junit.framework.TestCase) TestingModelFactory(org.apache.jena.rdf.model.test.helpers.TestingModelFactory)

Example 52 with TestCase

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);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) TestCase(junit.framework.TestCase) Module(com.intellij.openapi.module.Module)

Example 53 with TestCase

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;
}
Also used : TestSuite(junit.framework.TestSuite) TestCase(junit.framework.TestCase)

Example 54 with TestCase

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();
}
Also used : TestCase(junit.framework.TestCase) Test(junit.framework.Test) TestListener(junit.framework.TestListener) AssertionFailedError(junit.framework.AssertionFailedError)

Example 55 with TestCase

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()));
    }
}
Also used : TestCase(junit.framework.TestCase)

Aggregations

TestCase (junit.framework.TestCase)129 TestSuite (junit.framework.TestSuite)36 Test (junit.framework.Test)22 TestListener (junit.framework.TestListener)17 TestResult (junit.framework.TestResult)13 ArrayList (java.util.ArrayList)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 AssertionFailedError (junit.framework.AssertionFailedError)10 Constructor (java.lang.reflect.Constructor)8 Enumeration (java.util.Enumeration)6 Context (android.content.Context)5 PackageManager (android.content.pm.PackageManager)5 ResolveInfo (android.content.pm.ResolveInfo)5 Bundle (android.os.Bundle)5 HandlerThread (android.os.HandlerThread)5 ShellUiAutomatorBridge (com.android.uiautomator.core.ShellUiAutomatorBridge)5 Tracer (com.android.uiautomator.core.Tracer)5 UiAutomationShellWrapper (com.android.uiautomator.core.UiAutomationShellWrapper)5 Field (java.lang.reflect.Field)5 HashSet (java.util.HashSet)5