Search in sources :

Example 51 with Test

use of junit.framework.Test in project tomee by apache.

the class NumberedTestCase method run.

protected void run(final TestResult result, final Method testMethod) {
    final Test test = createTest(testMethod);
    result.startTest(test);
    final Protectable p = new Protectable() {

        public void protect() throws Throwable {
            runTestMethod(testMethod);
        }
    };
    // System.out.println(">>" + NumberedTestCase.class.getName() + "> started: " + testMethod.toGenericString());
    result.runProtected(test, p);
    result.endTest(test);
// System.out.println(">>" + NumberedTestCase.class.getName() + "> done: " + testMethod.toGenericString());
}
Also used : Test(junit.framework.Test) Protectable(junit.framework.Protectable)

Example 52 with Test

use of junit.framework.Test in project ignite by apache.

the class IgniteTestSuite method addTestMethod.

/**
 * Add test method.
 *
 * @param m Test method.
 * @param names Test name list.
 * @param theClass Test class.
 * @param clsIgnore Class ignore descriptor (if any).
 * @return Result.
 */
private AddResult addTestMethod(Method m, List<String> names, Class<?> theClass, @Nullable IgnoreDescriptor clsIgnore) {
    String name = m.getName();
    if (names.contains(name))
        return new AddResult(false, null);
    if (!isPublicTestMethod(m)) {
        if (isTestMethod(m))
            addTest(warning("Test method isn't public: " + m.getName() + "(" + theClass.getCanonicalName() + ")"));
        return new AddResult(false, null);
    }
    names.add(name);
    IgnoreDescriptor ignore = IgnoreDescriptor.forMethod(theClass, m);
    if (ignore == null)
        ignore = clsIgnore;
    if (ignoredOnly) {
        if (ignore != null) {
            Test test = createTest(theClass, name);
            if (ignore.forceFailure()) {
                if (test instanceof GridAbstractTest)
                    ((GridAbstractTest) test).forceFailure(ignore.reason());
                else
                    test = new ForcedFailure(name, ignore.reason());
            }
            addTest(test);
            return new AddResult(true, test);
        }
    } else {
        if (ignore == null) {
            Test test = createTest(theClass, name);
            addTest(test);
            return new AddResult(true, test);
        }
    }
    return new AddResult(false, null);
}
Also used : GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) Test(junit.framework.Test) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest)

Example 53 with Test

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

the class BaseTestRunner method getTest.

/**
	 * Returns the Test corresponding to the given suite. This is
	 * a template method, subclasses override runFailed(), clearStatus().
	 */
public Test getTest(String suiteClassName) {
    if (suiteClassName.length() <= 0) {
        clearStatus();
        return null;
    }
    Class<?> testClass = null;
    try {
        testClass = loadSuiteClass(suiteClassName);
    } catch (ClassNotFoundException e) {
        String clazz = e.getMessage();
        if (clazz == null)
            clazz = suiteClassName;
        runFailed("Class not found \"" + clazz + "\"");
        return null;
    } catch (Exception e) {
        runFailed("Error: " + e.toString());
        return null;
    }
    Method suiteMethod = null;
    try {
        suiteMethod = testClass.getMethod(SUITE_METHODNAME, new Class[0]);
    } catch (Exception e) {
        // try to extract a test suite automatically
        clearStatus();
        return new TestSuite(testClass);
    }
    if (!Modifier.isStatic(suiteMethod.getModifiers())) {
        runFailed("Suite() method must be static");
        return null;
    }
    Test test = null;
    try {
        // static method
        test = (Test) suiteMethod.invoke(null, (Object[]) new Class[0]);
        if (test == null)
            return test;
    } catch (InvocationTargetException e) {
        runFailed("Failed to invoke suite():" + e.getTargetException().toString());
        return null;
    } catch (IllegalAccessException e) {
        runFailed("Failed to invoke suite():" + e.toString());
        return null;
    }
    clearStatus();
    return test;
}
Also used : TestSuite(junit.framework.TestSuite) Test(junit.framework.Test) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 54 with Test

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

the class TestRunner method runSingleMethod.

protected TestResult runSingleMethod(String testCase, String method, boolean wait) throws Exception {
    Class<? extends TestCase> testClass = loadSuiteClass(testCase).asSubclass(TestCase.class);
    Test test = TestSuite.createTest(testClass, method);
    return doRun(test, wait);
}
Also used : Test(junit.framework.Test)

Example 55 with Test

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

the class TestCaseUtil method getTestCaseNames.

@SuppressWarnings("unchecked")
public static List<String> getTestCaseNames(Test test, boolean flatten) {
    List<Test> tests = (List<Test>) getTests(test, flatten);
    List<String> testCaseNames = Lists.newArrayList();
    for (Test aTest : tests) {
        testCaseNames.add(getTestName(aTest));
    }
    return testCaseNames;
}
Also used : Test(junit.framework.Test) List(java.util.List)

Aggregations

Test (junit.framework.Test)114 TestSuite (junit.framework.TestSuite)45 TestCase (junit.framework.TestCase)22 ArrayList (java.util.ArrayList)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 Method (java.lang.reflect.Method)12 AssertionFailedError (junit.framework.AssertionFailedError)12 TestListener (junit.framework.TestListener)11 TestResult (junit.framework.TestResult)11 TestDescriptor (android.test.suitebuilder.ListTestCaseNames.TestDescriptor)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)10 Enumeration (java.util.Enumeration)10 RepeatedTest (junit.extensions.RepeatedTest)7 AndroidTestRunner (android.test.AndroidTestRunner)5 Field (java.lang.reflect.Field)5 List (java.util.List)5 IOException (java.io.IOException)3 PrintWriter (java.io.PrintWriter)2 JUnit4TestAdapter (junit.framework.JUnit4TestAdapter)2 GridAbstractTest (org.apache.ignite.testframework.junits.GridAbstractTest)2