Search in sources :

Example 91 with TestCase

use of junit.framework.TestCase in project android_frameworks_base by ParanoidAndroid.

the class AndroidTestRunnerTest method testRunSingleTestMethod.

public void testRunSingleTestMethod() throws Exception {
    String testMethodName = "testTwo";
    mAndroidTestRunner.setTestClassName(TwoTestTestCase.class.getName(), testMethodName);
    List<TestCase> testCases = mAndroidTestRunner.getTestCases();
    List<String> testNames = Lists.newArrayList();
    for (TestCase testCase : testCases) {
        testNames.add(testCase.getName());
    }
    assertEquals(Arrays.asList(testMethodName), testNames);
}
Also used : TestCase(junit.framework.TestCase)

Example 92 with TestCase

use of junit.framework.TestCase in project android_frameworks_base by ParanoidAndroid.

the class TestCaseUtilTest method testGetTestCaseNamesForTestCaseWithSuiteMethod.

public void testGetTestCaseNamesForTestCaseWithSuiteMethod() throws Exception {
    TestCase testCase = new OneTestTestCaseWithSuite();
    List<String> testCaseNames = TestCaseUtil.getTestCaseNames(testCase, false);
    assertEquals(1, testCaseNames.size());
    assertTrue(testCaseNames.get(0).endsWith("testOne"));
}
Also used : TestCase(junit.framework.TestCase)

Example 93 with TestCase

use of junit.framework.TestCase in project powermock by powermock.

the class PowerMockJUnit4MethodValidator method validateTestMethods.

/**
     * This is a rip-off of the
     * {@link MethodValidator#validateInstanceMethods()} with the exception that
     * this method also searches for test methods if the class extends
     * {@link TestCase} and has methods that starts with test which are not
     * annotated.
     */
@SuppressWarnings("unchecked")
private void validateTestMethods(Class<? extends Annotation> annotation, boolean isStatic) {
    TestClass testClass = Whitebox.getInternalState(this, TEST_CLASS_FIELD, MethodValidator.class);
    Class<?> classUnderTest = Whitebox.getInternalState(testClass, CLASS_UNDER_TEST_FIELD);
    final List<Method> methods;
    if (TestCase.class.equals(classUnderTest.getSuperclass()) && !isStatic) {
        methods = getTestMethodsWithNoAnnotation(classUnderTest);
    } else {
        methods = testClass.getAnnotatedMethods(annotation);
    }
    List<Throwable> fErrors = Whitebox.getInternalState(this, ERRORS_FIELD, MethodValidator.class);
    for (Method each : methods) {
        if (Modifier.isStatic(each.getModifiers()) != isStatic) {
            String state = isStatic ? "should" : "should not";
            fErrors.add(new Exception("Method " + each.getName() + "() " + state + " be static"));
        }
        if (!Modifier.isPublic(each.getDeclaringClass().getModifiers()))
            fErrors.add(new Exception("Class " + each.getDeclaringClass().getName() + " should be public"));
        if (!Modifier.isPublic(each.getModifiers()))
            fErrors.add(new Exception("Method " + each.getName() + " should be public"));
        if (each.getReturnType() != Void.TYPE)
            fErrors.add(new Exception("Method " + each.getName() + " should be void"));
        if (each.getParameterTypes().length != 0)
            fErrors.add(new Exception("Method " + each.getName() + " should have no parameters"));
    }
}
Also used : TestCase(junit.framework.TestCase) TestClass(org.junit.internal.runners.TestClass) Method(java.lang.reflect.Method)

Example 94 with TestCase

use of junit.framework.TestCase in project robovm by robovm.

the class RoboVMAllTests method hasTests.

private static boolean hasTests(Test test) {
    if (test == null) {
        return false;
    }
    if (test.countTestCases() > 1) {
        return true;
    }
    if (!(test instanceof TestSuite)) {
        return true;
    }
    TestSuite suite = (TestSuite) test;
    if (!(suite.testAt(0) instanceof TestCase)) {
        return true;
    }
    TestCase singleTest = (TestCase) suite.testAt(0);
    return !singleTest.getName().equals("warning");
}
Also used : TestSuite(junit.framework.TestSuite) TestCase(junit.framework.TestCase)

Example 95 with TestCase

use of junit.framework.TestCase in project platform_frameworks_base by android.

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