use of io.cucumber.plugin.event.TestCase in project cucumber-jvm by cucumber.
the class EventBusTest method handlers_do_not_receive_the_events_they_did_not_registered_for.
@Test
void handlers_do_not_receive_the_events_they_did_not_registered_for() {
EventHandler handler = mock(EventHandler.class);
PickleStepTestStep testStep = mock(PickleStepTestStep.class);
TestCase testCase = mock(TestCase.class);
TestStepStarted event = new TestStepStarted(EPOCH, testCase, testStep);
EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
bus.registerHandlerFor(TestStepFinished.class, handler);
bus.send(event);
verify(handler, never()).receive(event);
}
use of io.cucumber.plugin.event.TestCase in project cucumber-jvm by cucumber.
the class TimelineFormatter method findRootNodeName.
private String findRootNodeName(TestCase testCase) {
Location location = testCase.getLocation();
Predicate<Node> withLocation = candidate -> candidate.getLocation().equals(location);
return parsedTestSources.get(testCase.getUri()).stream().map(node -> node.findPathTo(withLocation)).filter(Optional::isPresent).map(Optional::get).findFirst().map(nodes -> nodes.get(0)).flatMap(Node::getName).orElse("Unknown");
}
use of io.cucumber.plugin.event.TestCase in project cucumber-jvm by cucumber.
the class TimelineFormatter method handleTestCaseStarted.
private void handleTestCaseStarted(TestCaseStarted event) {
Thread thread = Thread.currentThread();
threadGroups.computeIfAbsent(thread.getId(), threadId -> {
GroupData group = new GroupData();
group.setContent(thread.toString());
group.setId(threadId);
return group;
});
TestCase testCase = event.getTestCase();
TestData data = new TestData();
data.setId(getId(event));
data.setFeature(findRootNodeName(testCase));
data.setScenario(testCase.getName());
data.setStart(event.getInstant().toEpochMilli());
data.setTags(buildTagsValue(testCase));
data.setGroup(thread.getId());
allTests.put(data.getId(), data);
}
use of io.cucumber.plugin.event.TestCase in project cucumber-jvm by cucumber.
the class JsonFormatter method createTestCase.
private Map<String, Object> createTestCase(TestCaseStarted event) {
Map<String, Object> testCaseMap = new HashMap<>();
testCaseMap.put("start_timestamp", getDateTimeFromTimeStamp(event.getInstant()));
TestCase testCase = event.getTestCase();
testCaseMap.put("name", testCase.getName());
testCaseMap.put("line", testCase.getLine());
testCaseMap.put("type", "scenario");
TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testCase.getLine());
if (astNode != null) {
testCaseMap.put("id", TestSourcesModel.calculateId(astNode));
Scenario scenarioDefinition = TestSourcesModel.getScenarioDefinition(astNode);
testCaseMap.put("keyword", scenarioDefinition.getKeyword());
testCaseMap.put("description", scenarioDefinition.getDescription() != null ? scenarioDefinition.getDescription() : "");
}
testCaseMap.put("steps", new ArrayList<Map<String, Object>>());
if (!testCase.getTags().isEmpty()) {
List<Map<String, Object>> tagList = new ArrayList<>();
for (String tag : testCase.getTags()) {
Map<String, Object> tagMap = new HashMap<>();
tagMap.put("name", tag);
tagList.add(tagMap);
}
testCaseMap.put("tags", tagList);
}
return testCaseMap;
}
use of io.cucumber.plugin.event.TestCase in project cucumber-jvm by cucumber.
the class PrettyFormatter method printScenarioDefinition.
private void printScenarioDefinition(TestCaseStarted event) {
TestCase testCase = event.getTestCase();
String definitionText = formatScenarioDefinition(testCase);
String path = relativize(testCase.getUri()).getSchemeSpecificPart();
String locationIndent = calculateLocationIndent(event.getTestCase(), SCENARIO_INDENT + definitionText);
out.println(SCENARIO_INDENT + definitionText + locationIndent + formatLocation(path + ":" + testCase.getLocation().getLine()));
}
Aggregations