Search in sources :

Example 11 with JUnitCore

use of org.junit.runner.JUnitCore in project randomizedtesting by randomizedtesting.

the class TestJUnit3MethodProvider method testJUnit3Overrides.

@Test
public void testJUnit3Overrides() throws Exception {
    Result r = new JUnitCore().run(new RandomizedRunner(S3.class));
    Assert.assertEquals(0, r.getFailureCount());
    Assert.assertEquals(1, r.getRunCount());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 12 with JUnitCore

use of org.junit.runner.JUnitCore in project robovm by robovm.

the class RoboVMAllTests method main.

public static void main(String[] args) throws Exception {
    System.out.println("JUnit version " + Version.id());
    JUnitCore core = new JUnitCore();
    core.addListener(new TextListener(System.out) {

        @Override
        public void testStarted(Description description) {
            System.out.print(description + " ... ");
        }

        @Override
        public void testFinished(Description description) {
            System.out.println();
        }

        @Override
        public void testFailure(Failure failure) {
            System.out.print("FAILED!");
        }

        @Override
        public void testIgnored(Description description) {
            System.out.println("IGNORED!");
        }
    });
    core.run(suite(Pattern.compile(args.length > 0 ? args[0] : ".*"), Pattern.compile(args.length > 1 ? args[1] : " "), false));
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) TextListener(org.junit.internal.TextListener) Failure(org.junit.runner.notification.Failure)

Example 13 with JUnitCore

use of org.junit.runner.JUnitCore 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 14 with JUnitCore

use of org.junit.runner.JUnitCore in project mockito by mockito.

the class MockInjectionUsingConstructorTest method constructor_is_called_for_each_test_in_test_class.

@Test
public void constructor_is_called_for_each_test_in_test_class() throws Exception {
    // given
    junit_test_with_3_tests_methods.constructor_instantiation = 0;
    JUnitCore jUnitCore = new JUnitCore();
    jUnitCore.addListener(new TextListener(System.out));
    // when
    jUnitCore.run(junit_test_with_3_tests_methods.class);
    // then
    assertThat(junit_test_with_3_tests_methods.constructor_instantiation).isEqualTo(3);
}
Also used : JUnitCore(org.junit.runner.JUnitCore) TextListener(org.junit.internal.TextListener) Test(org.junit.Test)

Example 15 with JUnitCore

use of org.junit.runner.JUnitCore in project mockito by mockito.

the class VerificationCollectorImplTest method should_invoke_collector_rule_after_test.

@Test
public void should_invoke_collector_rule_after_test() {
    JUnitCore runner = new JUnitCore();
    Result result = runner.run(VerificationCollectorRuleInner.class);
    assertThat(result.getFailureCount()).isEqualTo(1);
    assertThat(result.getFailures().get(0).getMessage()).contains("1. Wanted but not invoked:");
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result) Test(org.junit.Test)

Aggregations

JUnitCore (org.junit.runner.JUnitCore)173 Result (org.junit.runner.Result)104 Test (org.junit.Test)88 Request (org.junit.runner.Request)33 Failure (org.junit.runner.notification.Failure)24 PrintableResult.testResult (org.junit.experimental.results.PrintableResult.testResult)22 RunListener (org.junit.runner.notification.RunListener)17 Description (org.junit.runner.Description)16 ArrayList (java.util.ArrayList)14 TestResult (junit.framework.TestResult)14 TextListener (org.junit.internal.TextListener)12 Runner (org.junit.runner.Runner)9 RandomizedRunner (com.carrotsearch.randomizedtesting.RandomizedRunner)7 TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 OutputStream (java.io.OutputStream)5 CategoryFilter (org.junit.experimental.categories.Categories.CategoryFilter)5 File (java.io.File)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 InOrder (org.mockito.InOrder)4