Search in sources :

Example 1 with HtmlFormatter

use of io.cucumber.core.plugin.HtmlFormatter in project cucumber-jvm by cucumber.

the class CompatibilityTest method produces_expected_output_for.

@ParameterizedTest
@MethodSource("io.cucumber.compatibility.TestCase#testCases")
void produces_expected_output_for(TestCase testCase) throws IOException {
    Path parentDir = Files.createDirectories(Paths.get("target", "messages", testCase.getId()));
    Path outputNdjson = parentDir.resolve("out.ndjson");
    Path outputHtml = parentDir.resolve("out.html");
    Path outputJson = parentDir.resolve("out.json");
    try {
        Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().addGlue(testCase.getGlue()).addFeature(testCase.getFeature()).build()).withAdditionalPlugins(new MessageFormatter(newOutputStream(outputNdjson)), new HtmlFormatter(newOutputStream(outputHtml)), new JsonFormatter(newOutputStream(outputJson))).build().run();
    } catch (Exception ignored) {
    }
    List<JsonNode> expected = readAllMessages(testCase.getExpectedFile());
    List<JsonNode> actual = readAllMessages(outputNdjson);
    Map<String, List<JsonNode>> expectedEnvelopes = openEnvelopes(expected);
    Map<String, List<JsonNode>> actualEnvelopes = openEnvelopes(actual);
    // exception: Java step definitions are not in a predictable order
    // because Class#getMethods() does not return a predictable order.
    sortStepDefinitions(expectedEnvelopes);
    sortStepDefinitions(actualEnvelopes);
    // unknown-parameter-types
    if ("unknown-parameter-type".equals(testCase.getId())) {
        expectedEnvelopes.remove("testCase");
        expectedEnvelopes.remove("testCaseStarted");
        expectedEnvelopes.remove("testStepStarted");
        expectedEnvelopes.remove("testStepFinished");
        expectedEnvelopes.remove("testCaseFinished");
    }
    expectedEnvelopes.forEach((messageType, expectedMessages) -> assertThat(actualEnvelopes, hasEntry(is(messageType), containsInRelativeOrder(aComparableMessage(expectedMessages)))));
}
Also used : Path(java.nio.file.Path) JsonFormatter(io.cucumber.core.plugin.JsonFormatter) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) JsonNode(io.cucumber.messages.internal.com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) MessageFormatter(io.cucumber.core.plugin.MessageFormatter) HtmlFormatter(io.cucumber.core.plugin.HtmlFormatter) JsonProcessingException(io.cucumber.messages.internal.com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)1 HtmlFormatter (io.cucumber.core.plugin.HtmlFormatter)1 JsonFormatter (io.cucumber.core.plugin.JsonFormatter)1 MessageFormatter (io.cucumber.core.plugin.MessageFormatter)1 JsonProcessingException (io.cucumber.messages.internal.com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (io.cucumber.messages.internal.com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1