Search in sources :

Example 11 with NoTestsRemainException

use of org.junit.runner.manipulation.NoTestsRemainException in project bnd by bndtools.

the class Activator method addTest.

@SuppressWarnings("unchecked")
private void addTest(TestSuite suite, Class<?> clazz, final String method) {
    if (TestCase.class.isAssignableFrom(clazz)) {
        if (hasJunit4Annotations(clazz)) {
            error("The test class %s extends %s and it uses JUnit 4 annotations. This means that the annotations will be ignored.", clazz.getName(), TestCase.class.getName());
        }
        trace("using JUnit 3");
        if (method != null) {
            suite.addTest(TestSuite.createTest(clazz, method));
            return;
        }
        suite.addTestSuite((Class<? extends TestCase>) clazz);
        return;
    }
    trace("using JUnit 4");
    JUnit4TestAdapter adapter = new JUnit4TestAdapter(clazz);
    if (method != null) {
        trace("method specified " + clazz + ":" + method);
        final Pattern glob = Pattern.compile(method.replaceAll("\\*", ".*").replaceAll("\\?", ".?"));
        try {
            adapter.filter(new org.junit.runner.manipulation.Filter() {

                @Override
                public String describe() {
                    return "Method filter for " + method;
                }

                @Override
                public boolean shouldRun(Description description) {
                    if (glob.matcher(description.getMethodName()).lookingAt()) {
                        trace("accepted " + description.getMethodName());
                        return true;
                    }
                    trace("rejected " + description.getMethodName());
                    return false;
                }
            });
        } catch (NoTestsRemainException e) {
            return;
        }
    }
    suite.addTest(adapter);
}
Also used : Pattern(java.util.regex.Pattern) Description(org.junit.runner.Description) TestCase(junit.framework.TestCase) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) JUnit4TestAdapter(junit.framework.JUnit4TestAdapter)

Aggregations

NoTestsRemainException (org.junit.runner.manipulation.NoTestsRemainException)11 Runner (org.junit.runner.Runner)6 Filter (org.junit.runner.manipulation.Filter)6 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)2 Description (org.junit.runner.Description)2 Request (org.junit.runner.Request)2 Filterable (org.junit.runner.manipulation.Filterable)2 RunNotifier (org.junit.runner.notification.RunNotifier)2 MethodGlobFilter (com.carrotsearch.randomizedtesting.MethodGlobFilter)1 RegExTestCaseFilter (com.google.testing.junit.junit4.runner.RegExTestCaseFilter)1 SuiteTrimmingFilter (com.google.testing.junit.junit4.runner.SuiteTrimmingFilter)1 Bombed (com.intellij.idea.Bombed)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Method (java.lang.reflect.Method)1 Pattern (java.util.regex.Pattern)1 JUnit4TestAdapter (junit.framework.JUnit4TestAdapter)1