Search in sources :

Example 1 with Description

use of org.junit.runner.Description in project elasticsearch by elastic.

the class LoggingListenerTests method testTestRunStartedSupportsClassInDefaultPackage.

public void testTestRunStartedSupportsClassInDefaultPackage() throws Exception {
    LoggingListener loggingListener = new LoggingListener();
    Description description = Description.createTestDescription(Class.forName("Dummy"), "dummy");
    // Will throw an exception without the check for testClassPackage != null in testRunStarted
    loggingListener.testRunStarted(description);
}
Also used : Description(org.junit.runner.Description) LoggingListener(org.elasticsearch.test.junit.listeners.LoggingListener)

Example 2 with Description

use of org.junit.runner.Description in project elasticsearch by elastic.

the class LoggingListenerTests method testInvalidMethodTestLoggingAnnotation.

public void testInvalidMethodTestLoggingAnnotation() throws Exception {
    final LoggingListener loggingListener = new LoggingListener();
    final Description suiteDescription = Description.createSuiteDescription(InvalidMethod.class);
    loggingListener.testRunStarted(suiteDescription);
    final Method method = InvalidMethod.class.getMethod("invalidMethod");
    final TestLogging annotation = method.getAnnotation(TestLogging.class);
    Description testDescription = Description.createTestDescription(InvalidMethod.class, "invalidMethod", annotation);
    final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> loggingListener.testStarted(testDescription));
    assertThat(e.getMessage(), equalTo("invalid test logging annotation [abc:INFO:WARN]"));
}
Also used : Description(org.junit.runner.Description) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging) LoggingListener(org.elasticsearch.test.junit.listeners.LoggingListener) Method(java.lang.reflect.Method)

Example 3 with Description

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

the class ConsoleSpammingMockitoJUnitRunner method run.

@Override
public void run(RunNotifier notifier) {
    RunListener listener = new RunListener() {

        WarningsCollector warningsCollector;

        @Override
        public void testStarted(Description description) throws Exception {
            warningsCollector = new WarningsCollector();
        }

        @Override
        public void testFailure(Failure failure) throws Exception {
            logger.log(warningsCollector.getWarnings());
        }
    };
    notifier.addListener(listener);
    runner.run(notifier);
}
Also used : Description(org.junit.runner.Description) WarningsCollector(org.mockito.internal.debugging.WarningsCollector) Failure(org.junit.runner.notification.Failure) RunListener(org.junit.runner.notification.RunListener)

Example 4 with Description

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

the class VerboseMockitoJUnitRunner method run.

@Override
public void run(RunNotifier notifier) {
    //a listener that changes the failure's exception in a very hacky way...
    RunListener listener = new RunListener() {

        WarningsCollector warningsCollector;

        @Override
        public void testStarted(Description description) throws Exception {
            warningsCollector = new WarningsCollector();
        }

        @Override
        @SuppressWarnings("deprecation")
        public void testFailure(final Failure failure) throws Exception {
            String warnings = warningsCollector.getWarnings();
            new JUnitFailureHacker().appendWarnings(failure, warnings);
        }
    };
    notifier.addFirstListener(listener);
    runner.run(notifier);
}
Also used : Description(org.junit.runner.Description) JUnitFailureHacker(org.mockito.internal.junit.util.JUnitFailureHacker) WarningsCollector(org.mockito.internal.debugging.WarningsCollector) Failure(org.junit.runner.notification.Failure) RunListener(org.junit.runner.notification.RunListener)

Example 5 with Description

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

the class ConsoleSpammingMockitoJUnitRunnerTest method shouldDelegateToGetDescription.

//TODO add sensible tests
@Test
public void shouldDelegateToGetDescription() throws Exception {
    //given
    final Description expectedDescription = Description.createSuiteDescription(this.getClass());
    runner = new ConsoleSpammingMockitoJUnitRunner(loggerStub, new InternalRunnerStub() {

        public Description getDescription() {
            return expectedDescription;
        }
    });
    //when
    Description description = runner.getDescription();
    //then
    assertEquals(expectedDescription, description);
}
Also used : Description(org.junit.runner.Description) Test(org.junit.Test)

Aggregations

Description (org.junit.runner.Description)309 Test (org.junit.Test)119 Failure (org.junit.runner.notification.Failure)58 Result (org.junit.runner.Result)32 ArrayList (java.util.ArrayList)24 RunListener (org.junit.runner.notification.RunListener)24 IOException (java.io.IOException)22 Request (org.junit.runner.Request)21 Method (java.lang.reflect.Method)18 JUnitCore (org.junit.runner.JUnitCore)17 Test (org.junit.jupiter.api.Test)14 Filter (org.junit.runner.manipulation.Filter)14 File (java.io.File)13 Runner (org.junit.runner.Runner)13 RunNotifier (org.junit.runner.notification.RunNotifier)13 Statement (org.junit.runners.model.Statement)13 LoggingListener (org.elasticsearch.test.junit.listeners.LoggingListener)12 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)10 ComparisonFailure (org.junit.ComparisonFailure)10 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)9