Search in sources :

Example 61 with Test

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

the class FilteredTestSuite method filter.

public static List<Test> filter(final List<Test> tests) {
    final String itest = System.getProperty("itest");
    if (itest == null) {
        return tests;
    }
    final ArrayList<Test> filtered = new ArrayList<Test>();
    for (final Test test : tests) {
        final String simpleName = test.getClass().getSimpleName();
        if (simpleName.matches(itest)) {
            filtered.add(test);
        }
    }
    return filtered;
}
Also used : Test(junit.framework.Test) ArrayList(java.util.ArrayList)

Example 62 with Test

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

the class TestSuite method run.

/**
 * Runs the tests and collects their result in a TestResult.
 */
public void run(final TestResult result) {
    try {
        final List<Test> tests = getTests();
        if (tests.size() == 0)
            return;
        setUp();
        try {
            for (final Test test : tests) {
                if (result.shouldStop())
                    break;
                test.run(result);
            }
        } finally {
            tearDown();
        }
    } catch (final Exception e) {
        result.addError(this, e);
    }
}
Also used : Test(junit.framework.Test)

Example 63 with Test

use of junit.framework.Test in project junit4 by junit-team.

the class SuiteMethod method testFromSuiteMethod.

public static Test testFromSuiteMethod(Class<?> klass) throws Throwable {
    Method suiteMethod = null;
    Test suite = null;
    try {
        suiteMethod = klass.getMethod("suite");
        if (!Modifier.isStatic(suiteMethod.getModifiers())) {
            throw new Exception(klass.getName() + ".suite() must be static");
        }
        // static method
        suite = (Test) suiteMethod.invoke(null);
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
    return suite;
}
Also used : Test(junit.framework.Test) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 64 with Test

use of junit.framework.Test in project junit4 by junit-team.

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 65 with Test

use of junit.framework.Test in project junit4 by junit-team.

the class TestRunner method start.

/**
     * Starts a test run. Analyzes the command line arguments and runs the given
     * test suite.
     */
public TestResult start(String[] args) throws Exception {
    String testCase = "";
    String method = "";
    boolean wait = false;
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-wait")) {
            wait = true;
        } else if (args[i].equals("-c")) {
            testCase = extractClassName(args[++i]);
        } else if (args[i].equals("-m")) {
            String arg = args[++i];
            int lastIndex = arg.lastIndexOf('.');
            testCase = arg.substring(0, lastIndex);
            method = arg.substring(lastIndex + 1);
        } else if (args[i].equals("-v")) {
            System.err.println("JUnit " + Version.id() + " by Kent Beck and Erich Gamma");
        } else {
            testCase = args[i];
        }
    }
    if (testCase.equals("")) {
        throw new Exception("Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class");
    }
    try {
        if (!method.equals("")) {
            return runSingleMethod(testCase, method, wait);
        }
        Test suite = getTest(testCase);
        return doRun(suite, wait);
    } catch (Exception e) {
        throw new Exception("Could not create and run test suite: " + e);
    }
}
Also used : Test(junit.framework.Test)

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