Search in sources :

Example 41 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class RuntimeTest method should_make_scenario_name_available_to_hooks.

@Test
public void should_make_scenario_name_available_to_hooks() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    HookDefinition beforeHook = mock(HookDefinition.class);
    when(beforeHook.matches(anyCollectionOf(Tag.class))).thenReturn(true);
    Runtime runtime = createRuntimeWithMockedGlue(mock(StepDefinitionMatch.class), beforeHook, true);
    feature.run(mock(Formatter.class), mock(Reporter.class), runtime);
    ArgumentCaptor<Scenario> capturedScenario = ArgumentCaptor.forClass(Scenario.class);
    verify(beforeHook).execute(capturedScenario.capture());
    assertEquals("scenario name", capturedScenario.getValue().getName());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) JSONFormatter(gherkin.formatter.JSONFormatter) Formatter(gherkin.formatter.Formatter) CucumberJSONFormatter(cucumber.runtime.formatter.CucumberJSONFormatter) StepDefinitionReporter(cucumber.api.StepDefinitionReporter) Reporter(gherkin.formatter.Reporter) Tag(gherkin.formatter.model.Tag) Scenario(cucumber.api.Scenario) Test(org.junit.Test)

Example 42 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class HookTest method after_hooks_execute_before_objects_are_disposed.

/**
     * Test for <a href="https://github.com/cucumber/cucumber-jvm/issues/23">#23</a>.
     * TODO: ensure this is no longer needed with the alternate approach taken in Runtime
     * TODO: this test is rather brittle, since there's lots of mocking :(
     */
@Test
public void after_hooks_execute_before_objects_are_disposed() throws Throwable {
    Backend backend = mock(Backend.class);
    HookDefinition hook = mock(HookDefinition.class);
    when(hook.matches(anyListOf(Tag.class))).thenReturn(true);
    gherkin.formatter.model.Scenario gherkinScenario = mock(gherkin.formatter.model.Scenario.class);
    CucumberFeature feature = mock(CucumberFeature.class);
    Feature gherkinFeature = mock(Feature.class);
    when(feature.getGherkinFeature()).thenReturn(gherkinFeature);
    when(gherkinFeature.getTags()).thenReturn(new ArrayList<Tag>());
    CucumberScenario scenario = new CucumberScenario(feature, null, gherkinScenario);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    RuntimeOptions runtimeOptions = new RuntimeOptions("");
    Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions);
    runtime.getGlue().addAfterHook(hook);
    scenario.run(mock(Formatter.class), mock(Reporter.class), runtime);
    InOrder inOrder = inOrder(hook, backend);
    inOrder.verify(hook).execute(Matchers.<Scenario>any());
    inOrder.verify(backend).disposeWorld();
}
Also used : InOrder(org.mockito.InOrder) Formatter(gherkin.formatter.Formatter) Reporter(gherkin.formatter.Reporter) CucumberScenario(cucumber.runtime.model.CucumberScenario) CucumberFeature(cucumber.runtime.model.CucumberFeature) Feature(gherkin.formatter.model.Feature) CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Tag(gherkin.formatter.model.Tag) Test(org.junit.Test)

Example 43 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class ExecutionUnitRunnerTest method shouldUseStepKeyworkAndNameForChildName.

@Test
public void shouldUseStepKeyworkAndNameForChildName() throws Exception {
    CucumberFeature cucumberFeature = TestFeatureBuilder.feature("featurePath", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Then it works\n");
    ExecutionUnitRunner runner = new ExecutionUnitRunner(null, (CucumberScenario) cucumberFeature.getFeatureElements().get(0), createStandardJUnitReporter());
    assertEquals("Then it works", runner.getDescription().getChildren().get(0).getMethodName());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) Test(org.junit.Test)

Example 44 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class ExecutionUnitRunnerTest method shouldUseScenarioNameForRunnerName.

@Test
public void shouldUseScenarioNameForRunnerName() throws Exception {
    CucumberFeature cucumberFeature = TestFeatureBuilder.feature("featurePath", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Then it works\n");
    ExecutionUnitRunner runner = new ExecutionUnitRunner(null, (CucumberScenario) cucumberFeature.getFeatureElements().get(0), createStandardJUnitReporter());
    assertEquals("Scenario: scenario name", runner.getName());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) Test(org.junit.Test)

Example 45 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class ExecutionUnitRunnerTest method shouldIncludeScenarioNameAsClassNameInStepDescriptions.

@Test
public void shouldIncludeScenarioNameAsClassNameInStepDescriptions() throws Exception {
    List<CucumberFeature> features = CucumberFeature.load(new ClasspathResourceLoader(this.getClass().getClassLoader()), asList("cucumber/runtime/junit/feature_with_same_steps_in_different_scenarios.feature"), Collections.emptyList());
    ExecutionUnitRunner runner = new ExecutionUnitRunner(null, (CucumberScenario) features.get(0).getFeatureElements().get(0), createStandardJUnitReporter());
    // fish out the data from runner
    Step step = runner.getChildren().get(0);
    Description runnerDescription = runner.getDescription();
    Description stepDescription = runnerDescription.getChildren().get(0);
    assertEquals("description includes scenario name as class name", runner.getName(), stepDescription.getClassName());
    assertEquals("description includes step keyword and name as method name", step.getKeyword() + step.getName(), stepDescription.getMethodName());
}
Also used : Description(org.junit.runner.Description) CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Step(gherkin.formatter.model.Step) Test(org.junit.Test)

Aggregations

CucumberFeature (cucumber.runtime.model.CucumberFeature)64 Test (org.junit.Test)53 HashMap (java.util.HashMap)33 Result (gherkin.formatter.model.Result)32 ArrayList (java.util.ArrayList)19 SimpleEntry (java.util.AbstractMap.SimpleEntry)10 ClasspathResourceLoader (cucumber.runtime.io.ClasspathResourceLoader)6 Resource (cucumber.runtime.io.Resource)6 Formatter (gherkin.formatter.Formatter)5 Reporter (gherkin.formatter.Reporter)5 StepDefinitionReporter (cucumber.api.StepDefinitionReporter)4 Step (gherkin.formatter.model.Step)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Matchers.anyString (org.mockito.Matchers.anyString)4 CucumberJSONFormatter (cucumber.runtime.formatter.CucumberJSONFormatter)3 CucumberTagStatement (cucumber.runtime.model.CucumberTagStatement)3 JSONFormatter (gherkin.formatter.JSONFormatter)3 Tag (gherkin.formatter.model.Tag)3 Description (org.junit.runner.Description)3 Scenario (cucumber.api.Scenario)2