Search in sources :

Example 1 with NoTestsRemainException

use of org.junit.runner.manipulation.NoTestsRemainException in project junit4 by junit-team.

the class ParentRunnerFilteringTest method testSuiteFiltering.

@Test
public void testSuiteFiltering() throws Exception {
    Runner runner = Request.aClass(ExampleSuite.class).getRunner();
    Filter filter = notThisMethodName("test1");
    try {
        filter.apply(runner);
    } catch (NoTestsRemainException e) {
        return;
    }
    fail("Expected 'NoTestsRemainException' due to complete filtering");
}
Also used : Runner(org.junit.runner.Runner) Filter(org.junit.runner.manipulation.Filter) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) Test(org.junit.Test)

Example 2 with NoTestsRemainException

use of org.junit.runner.manipulation.NoTestsRemainException in project junit4 by junit-team.

the class ParentRunnerFilteringTest method testSuiteFilteringWithUnmodifyableChildList.

@Test
public void testSuiteFilteringWithUnmodifyableChildList() throws Exception {
    Runner runner = Request.aClass(ExampleSuiteWithUnmodifyableChildList.class).getRunner();
    Filter filter = notThisMethodName("test1");
    try {
        filter.apply(runner);
    } catch (NoTestsRemainException e) {
        return;
    }
    fail("Expected 'NoTestsRemainException' due to complete filtering");
}
Also used : Runner(org.junit.runner.Runner) Filter(org.junit.runner.manipulation.Filter) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) Test(org.junit.Test)

Example 3 with NoTestsRemainException

use of org.junit.runner.manipulation.NoTestsRemainException in project junit4 by junit-team.

the class FilterRequest method getRunner.

@Override
public Runner getRunner() {
    try {
        Runner runner = request.getRunner();
        fFilter.apply(runner);
        return runner;
    } catch (NoTestsRemainException e) {
        return new ErrorReportingRunner(Filter.class, new Exception(String.format("No tests found matching %s from %s", fFilter.describe(), request.toString())));
    }
}
Also used : ErrorReportingRunner(org.junit.internal.runners.ErrorReportingRunner) Runner(org.junit.runner.Runner) Filter(org.junit.runner.manipulation.Filter) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) ErrorReportingRunner(org.junit.internal.runners.ErrorReportingRunner) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException)

Example 4 with NoTestsRemainException

use of org.junit.runner.manipulation.NoTestsRemainException in project junit4 by junit-team.

the class JUnit38ClassRunner method filter.

public void filter(Filter filter) throws NoTestsRemainException {
    if (getTest() instanceof Filterable) {
        Filterable adapter = (Filterable) getTest();
        adapter.filter(filter);
    } else if (getTest() instanceof TestSuite) {
        TestSuite suite = (TestSuite) getTest();
        TestSuite filtered = new TestSuite(suite.getName());
        int n = suite.testCount();
        for (int i = 0; i < n; i++) {
            Test test = suite.testAt(i);
            if (filter.shouldRun(makeDescription(test))) {
                filtered.addTest(test);
            }
        }
        setTest(filtered);
        if (filtered.testCount() == 0) {
            throw new NoTestsRemainException();
        }
    }
}
Also used : TestSuite(junit.framework.TestSuite) Test(junit.framework.Test) Filterable(org.junit.runner.manipulation.Filterable) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException)

Example 5 with NoTestsRemainException

use of org.junit.runner.manipulation.NoTestsRemainException in project pinpoint by naver.

the class PinpointPluginTestRunner method filter.

@Override
public void filter(Filter filter) throws NoTestsRemainException {
    synchronized (childrenLock) {
        List<FrameworkMethod> children = new ArrayList<FrameworkMethod>(getFilteredChildren());
        for (Iterator<FrameworkMethod> iter = children.iterator(); iter.hasNext(); ) {
            FrameworkMethod each = iter.next();
            if (shouldRun(filter, each)) {
                try {
                    filter.apply(each);
                } catch (NoTestsRemainException e) {
                    iter.remove();
                }
            } else {
                iter.remove();
            }
        }
        filteredChildren = Collections.unmodifiableCollection(children);
        if (filteredChildren.isEmpty()) {
            throw new NoTestsRemainException();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

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