Search in sources :

Example 86 with Description

use of org.junit.runner.Description in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method step_descriptions_can_be_turned_on.

@Test
void step_descriptions_can_be_turned_on() {
    Feature cucumberFeature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Background:\n" + "    Given background step\n" + "  Scenario: A\n" + "    Then scenario name\n" + "  Scenario: B\n" + "    Then scenario name\n" + "  Scenario Outline: C\n" + "    Then scenario <name>\n" + "  Examples:\n" + "    | name |\n" + "    | C    |\n" + "    | D    |\n" + "    | E    |\n");
    JUnitOptions junitOption = new JUnitOptionsBuilder().setStepNotifications(true).build();
    FeatureRunner runner = createFeatureRunner(cucumberFeature, junitOption);
    Description feature = runner.getDescription();
    Description scenarioA = feature.getChildren().get(0);
    assertThat(scenarioA.getChildren().size(), is(equalTo(2)));
    Description scenarioB = feature.getChildren().get(1);
    assertThat(scenarioB.getChildren().size(), is(equalTo(2)));
    Description scenarioC0 = feature.getChildren().get(2);
    assertThat(scenarioC0.getChildren().size(), is(equalTo(2)));
    Description scenarioC1 = feature.getChildren().get(3);
    assertThat(scenarioC1.getChildren().size(), is(equalTo(2)));
    Description scenarioC2 = feature.getChildren().get(4);
    assertThat(scenarioC2.getChildren().size(), is(equalTo(2)));
}
Also used : Description(org.junit.runner.Description) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 87 with Description

use of org.junit.runner.Description in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method should_populate_descriptions_with_stable_unique_ids.

@Test
void should_populate_descriptions_with_stable_unique_ids() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Background:\n" + "    Given background step\n" + "  Scenario: A\n" + "    Then scenario name\n" + "  Scenario: B\n" + "    Then scenario name\n" + "  Scenario Outline: C\n" + "    Then scenario <name>\n" + "  Examples:\n" + "    | name |\n" + "    | C    |\n" + "    | D    |\n" + "    | E    |\n");
    FeatureRunner runner = createFeatureRunner(feature, new JUnitOptions());
    FeatureRunner rerunner = createFeatureRunner(feature, new JUnitOptions());
    Set<Description> descriptions = new HashSet<>();
    assertDescriptionIsUnique(runner.getDescription(), descriptions);
    assertDescriptionIsPredictable(runner.getDescription(), descriptions);
    assertDescriptionIsPredictable(rerunner.getDescription(), descriptions);
}
Also used : Description(org.junit.runner.Description) Feature(io.cucumber.core.gherkin.Feature) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 88 with Description

use of org.junit.runner.Description in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method should_notify_of_failure_to_create_runners_and_request_test_execution_to_stop.

@Test
void should_notify_of_failure_to_create_runners_and_request_test_execution_to_stop() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario_1 name\n" + "    Given step #1\n");
    Filters filters = new Filters(RuntimeOptions.defaultOptions());
    IllegalStateException illegalStateException = new IllegalStateException();
    RunnerSupplier runnerSupplier = () -> {
        throw illegalStateException;
    };
    TimeServiceEventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    RuntimeOptions options = RuntimeOptions.defaultOptions();
    CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
    FeatureRunner featureRunner = FeatureRunner.create(feature, null, filters, context, new JUnitOptions());
    RunNotifier notifier = mock(RunNotifier.class);
    PickleRunners.PickleRunner pickleRunner = featureRunner.getChildren().get(0);
    featureRunner.runChild(pickleRunner, notifier);
    Description description = pickleRunner.getDescription();
    ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
    InOrder order = inOrder(notifier);
    order.verify(notifier).fireTestStarted(description);
    order.verify(notifier).fireTestFailure(failureArgumentCaptor.capture());
    assertThat(failureArgumentCaptor.getValue().getException(), is(equalTo(illegalStateException)));
    assertThat(failureArgumentCaptor.getValue().getDescription(), is(equalTo(description)));
    order.verify(notifier).pleaseStop();
    order.verify(notifier).fireTestFinished(description);
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) Feature(io.cucumber.core.gherkin.Feature) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ExitStatus(io.cucumber.core.runtime.ExitStatus) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) Filters(io.cucumber.core.filter.Filters) RunnerSupplier(io.cucumber.core.runtime.RunnerSupplier) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Failure(org.junit.runner.notification.Failure) Test(org.junit.jupiter.api.Test)

Example 89 with Description

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

the class UnnecessaryStubbingsReporter method validateUnusedStubs.

public void validateUnusedStubs(Class<?> testClass, RunNotifier notifier) {
    Collection<Invocation> unused = new UnusedStubbingsFinder().getUnusedStubbingsByLocation(mocks);
    if (unused.isEmpty()) {
        // whoa!!! All stubbings were used!
        return;
    }
    // Oups, there are unused stubbings
    Description unnecessaryStubbings = Description.createTestDescription(testClass, "unnecessary Mockito stubbings");
    notifier.fireTestFailure(new Failure(unnecessaryStubbings, Reporter.formatUnncessaryStubbingException(testClass, unused)));
}
Also used : Description(org.junit.runner.Description) Invocation(org.mockito.invocation.Invocation) Failure(org.junit.runner.notification.Failure)

Example 90 with Description

use of org.junit.runner.Description in project restfuse by eclipsesource.

the class RequestConfiguration_Test method testPathWithNonExistingSegments.

@Test(expected = IllegalStateException.class)
public void testPathWithNonExistingSegments() {
    Description method = mock(Description.class);
    HttpTest annotation = createAnnotation("/people/{invalid}/name");
    when(method.getAnnotation(HttpTest.class)).thenReturn(annotation);
    RequestConfiguration config = new RequestConfiguration("http://www.fake.com", method, new Object());
    RequestContext context = new RequestContext();
    context.addPathSegment("id", "12345");
    config.createRequest(context);
}
Also used : HttpTest(com.eclipsesource.restfuse.annotation.HttpTest) Description(org.junit.runner.Description) RequestContext(com.eclipsesource.restfuse.RequestContext) Test(org.junit.Test) HttpTest(com.eclipsesource.restfuse.annotation.HttpTest)

Aggregations

Description (org.junit.runner.Description)309 Test (org.junit.Test)119 Failure (org.junit.runner.notification.Failure)57 Result (org.junit.runner.Result)32 ArrayList (java.util.ArrayList)25 RunListener (org.junit.runner.notification.RunListener)23 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 Statement (org.junit.runners.model.Statement)13 LoggingListener (org.elasticsearch.test.junit.listeners.LoggingListener)12 RunNotifier (org.junit.runner.notification.RunNotifier)12 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)10 ComparisonFailure (org.junit.ComparisonFailure)10 Description.createTestDescription (org.junit.runner.Description.createTestDescription)9