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());
}
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();
}
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());
}
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());
}
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());
}
Aggregations