Search in sources :

Example 36 with Description

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

the class ParentRunnerFilteringTest method testCountClassFiltering.

@Test
public void testCountClassFiltering() throws Exception {
    JUnitCore junitCore = new JUnitCore();
    Request request = Request.aClass(ExampleTest.class);
    CountingFilter countingFilter = new CountingFilter();
    Request requestFiltered = request.filterWith(countingFilter);
    Result result = junitCore.run(requestFiltered);
    assertEquals(1, result.getRunCount());
    assertEquals(0, result.getFailureCount());
    Description desc = createTestDescription(ExampleTest.class, "test1");
    assertEquals(1, countingFilter.getCount(desc));
}
Also used : Description.createTestDescription(org.junit.runner.Description.createTestDescription) Description(org.junit.runner.Description) Description.createSuiteDescription(org.junit.runner.Description.createSuiteDescription) JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) Result(org.junit.runner.Result) PrintableResult.testResult(org.junit.experimental.results.PrintableResult.testResult) Test(org.junit.Test)

Example 37 with Description

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

the class ListenerTest method notifyListenersInTheOrderInWhichTheyAreAdded.

@Test
public void notifyListenersInTheOrderInWhichTheyAreAdded() {
    JUnitCore core = new JUnitCore();
    log = "";
    core.addListener(new RunListener() {

        @Override
        public void testRunStarted(Description description) throws Exception {
            log += "first ";
        }
    });
    core.addListener(new RunListener() {

        @Override
        public void testRunStarted(Description description) throws Exception {
            log += "second ";
        }
    });
    core.run(OneTest.class);
    assertEquals("first second ", log);
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test)

Example 38 with Description

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

the class RunnerTest method testFinished.

@Test
public void testFinished() {
    JUnitCore runner = new JUnitCore();
    wasRun = false;
    RunListener listener = new MyListener() {

        @Override
        public void testFinished(Description description) {
            wasRun = true;
        }
    };
    runner.addListener(listener);
    runner.run(NewExample.class);
    assertTrue(wasRun);
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test)

Example 39 with Description

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

the class JUnit38ClassRunnerTest method testListener.

@Test
public void testListener() throws Exception {
    JUnitCore runner = new JUnitCore();
    RunListener listener = new RunListener() {

        @Override
        public void testStarted(Description description) {
            assertEquals(Description.createTestDescription(OneTest.class, "testOne"), description);
            count++;
        }
    };
    runner.addListener(listener);
    count = 0;
    Result result = runner.run(OneTest.class);
    assertEquals(1, count);
    assertEquals(1, result.getRunCount());
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) RunListener(org.junit.runner.notification.RunListener) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 40 with Description

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

the class SingleMethodTest method filteringAwayEverythingThrowsException.

@Test(expected = NoTestsRemainException.class)
public void filteringAwayEverythingThrowsException() throws NoTestsRemainException {
    Filterable runner = (Filterable) Request.aClass(OneTimeSetup.class).getRunner();
    runner.filter(new Filter() {

        @Override
        public boolean shouldRun(Description description) {
            return false;
        }

        @Override
        public String describe() {
            return null;
        }
    });
}
Also used : Description(org.junit.runner.Description) Filter(org.junit.runner.manipulation.Filter) Filterable(org.junit.runner.manipulation.Filterable) Test(org.junit.Test)

Aggregations

Description (org.junit.runner.Description)190 Test (org.junit.Test)84 Failure (org.junit.runner.notification.Failure)42 Result (org.junit.runner.Result)27 ArrayList (java.util.ArrayList)20 Request (org.junit.runner.Request)20 RunListener (org.junit.runner.notification.RunListener)20 JUnitCore (org.junit.runner.JUnitCore)16 IOException (java.io.IOException)14 Method (java.lang.reflect.Method)12 Filter (org.junit.runner.manipulation.Filter)12 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)10 Runner (org.junit.runner.Runner)9 RunNotifier (org.junit.runner.notification.RunNotifier)9 ComparisonFailure (org.junit.ComparisonFailure)8 Statement (org.junit.runners.model.Statement)8 InOrder (org.mockito.InOrder)8 TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)7 Subscribe (com.google.common.eventbus.Subscribe)6 Step (gherkin.formatter.model.Step)6