Search in sources :

Example 1 with Request

use of org.junit.runner.Request in project buck by facebook.

the class JUnitRunner method run.

@Override
public void run() throws Throwable {
    Level stdOutLogLevel = Level.INFO;
    Level stdErrLogLevel = Level.WARNING;
    String unparsedStdOutLogLevel = System.getProperty(STD_OUT_LOG_LEVEL_PROPERTY);
    String unparsedStdErrLogLevel = System.getProperty(STD_ERR_LOG_LEVEL_PROPERTY);
    if (unparsedStdOutLogLevel != null) {
        stdOutLogLevel = Level.parse(unparsedStdOutLogLevel);
    }
    if (unparsedStdErrLogLevel != null) {
        stdErrLogLevel = Level.parse(unparsedStdErrLogLevel);
    }
    for (String className : testClassNames) {
        final Class<?> testClass = Class.forName(className);
        List<TestResult> results = new ArrayList<>();
        RecordingFilter filter = new RecordingFilter();
        if (mightBeATestClass(testClass)) {
            JUnitCore jUnitCore = new JUnitCore();
            Runner suite = new Computer().getSuite(createRunnerBuilder(), new Class<?>[] { testClass });
            Request request = Request.runner(suite);
            request = request.filterWith(filter);
            jUnitCore.addListener(new TestListener(results, stdOutLogLevel, stdErrLogLevel));
            jUnitCore.run(request);
        }
        // Combine the results with the tests we filtered out
        List<TestResult> actualResults = combineResults(results, filter.filteredOut);
        writeResult(className, actualResults);
    }
}
Also used : Runner(org.junit.runner.Runner) JUnitCore(org.junit.runner.JUnitCore) ArrayList(java.util.ArrayList) Computer(org.junit.runner.Computer) Request(org.junit.runner.Request) Level(java.util.logging.Level)

Example 2 with Request

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

the class CategoryTest method testCountWithMultipleExcludeFilter.

@Test
@SuppressWarnings("unchecked")
public void testCountWithMultipleExcludeFilter() throws Throwable {
    Set<Class<?>> exclusions = new HashSet<Class<?>>(2);
    Collections.addAll(exclusions, SlowTests.class, FastTests.class);
    CategoryFilter exclude = CategoryFilter.categoryFilter(true, null, true, exclusions);
    Request baseRequest = Request.aClass(OneOfEach.class);
    Result result = new JUnitCore().run(baseRequest.filterWith(exclude));
    assertTrue(result.wasSuccessful());
    assertEquals(1, result.getRunCount());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) HashSet(java.util.HashSet) CategoryFilter(org.junit.experimental.categories.Categories.CategoryFilter) Result(org.junit.runner.Result) PrintableResult.testResult(org.junit.experimental.results.PrintableResult.testResult) Test(org.junit.Test)

Example 3 with Request

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

the class CategoryTest method testCountWithExplicitIncludeFilter.

@Test
public void testCountWithExplicitIncludeFilter() throws Throwable {
    CategoryFilter include = CategoryFilter.include(SlowTests.class);
    Request baseRequest = Request.aClass(TestSuiteWithNoCategories.class);
    Result result = new JUnitCore().run(baseRequest.filterWith(include));
    assertTrue(result.wasSuccessful());
    assertEquals(2, result.getRunCount());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) CategoryFilter(org.junit.experimental.categories.Categories.CategoryFilter) Result(org.junit.runner.Result) PrintableResult.testResult(org.junit.experimental.results.PrintableResult.testResult) Test(org.junit.Test)

Example 4 with Request

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

the class CategoryTest method testCountWithExplicitExcludeFilter.

@Test
public void testCountWithExplicitExcludeFilter() throws Throwable {
    CategoryFilter include = CategoryFilter.exclude(SlowTests.class);
    Request baseRequest = Request.aClass(TestSuiteWithNoCategories.class);
    Result result = new JUnitCore().run(baseRequest.filterWith(include));
    assertEquals(2, result.getFailureCount());
    assertEquals(2, result.getRunCount());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) CategoryFilter(org.junit.experimental.categories.Categories.CategoryFilter) Result(org.junit.runner.Result) PrintableResult.testResult(org.junit.experimental.results.PrintableResult.testResult) Test(org.junit.Test)

Example 5 with Request

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

the class TheoryTestUtils method runTheoryClass.

public static Result runTheoryClass(Class<?> testClass) throws InitializationError {
    Runner theoryRunner = new Theories(testClass);
    Request request = Request.runner(theoryRunner);
    return new JUnitCore().run(request);
}
Also used : Runner(org.junit.runner.Runner) JUnitCore(org.junit.runner.JUnitCore) Theories(org.junit.experimental.theories.Theories) Request(org.junit.runner.Request)

Aggregations

Request (org.junit.runner.Request)54 Test (org.junit.Test)37 JUnitCore (org.junit.runner.JUnitCore)32 Result (org.junit.runner.Result)22 Description (org.junit.runner.Description)20 TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)8 Runner (org.junit.runner.Runner)8 PrintableResult.testResult (org.junit.experimental.results.PrintableResult.testResult)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 RunListener (org.junit.runner.notification.RunListener)6 OutputStream (java.io.OutputStream)5 CategoryFilter (org.junit.experimental.categories.Categories.CategoryFilter)5 Filter (org.junit.runner.manipulation.Filter)5 Failure (org.junit.runner.notification.Failure)5 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 InOrder (org.mockito.InOrder)4 ArrayList (java.util.ArrayList)3 Computer (org.junit.runner.Computer)3 TestNode (com.google.testing.junit.runner.model.TestNode)2