Search in sources :

Example 1 with ClockStub

use of io.cucumber.core.runner.ClockStub in project cucumber-jvm by cucumber.

the class PluginFactoryTest method plugin_does_not_buffer_its_output.

@Test
void plugin_does_not_buffer_its_output() {
    PrintStream previousSystemOut = System.out;
    OutputStream mockSystemOut = new ByteArrayOutputStream();
    try {
        System.setOut(new PrintStream(mockSystemOut));
        // Need to create a new plugin factory here since we need it to pick
        // up the new value of System.out
        fc = new PluginFactory();
        PluginOption option = parse("progress");
        ProgressFormatter plugin = (ProgressFormatter) fc.create(option);
        EventBus bus = new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID);
        plugin.setEventPublisher(bus);
        Result result = new Result(Status.PASSED, ZERO, null);
        TestStepFinished event = new TestStepFinished(bus.getInstant(), mock(TestCase.class), mock(PickleStepTestStep.class), result);
        bus.send(event);
        assertThat(mockSystemOut.toString(), is(not(equalTo(""))));
    } finally {
        System.setOut(previousSystemOut);
    }
}
Also used : PrintStream(java.io.PrintStream) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ClockStub(io.cucumber.core.runner.ClockStub) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Result(io.cucumber.plugin.event.Result) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) PluginOption(io.cucumber.core.options.PluginOption) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 2 with ClockStub

use of io.cucumber.core.runner.ClockStub in project cucumber-jvm by cucumber.

the class JsonParallelRuntimeTest method testSingleFeature.

@Test
void testSingleFeature() {
    ByteArrayOutputStream parallel = new ByteArrayOutputStream();
    Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(3).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/JsonPrettyFormatterTest.feature")).build()).withAdditionalPlugins(new JsonFormatter(parallel)).withEventBus(new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID)).build().run();
    ByteArrayOutputStream serial = new ByteArrayOutputStream();
    Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(1).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/JsonPrettyFormatterTest.feature")).build()).withAdditionalPlugins(new JsonFormatter(serial)).withEventBus(new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID)).build().run();
    assertThat(parallel.toString(), sameJSONAs(serial.toString()).allowingAnyArrayOrdering());
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) ClockStub(io.cucumber.core.runner.ClockStub) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 3 with ClockStub

use of io.cucumber.core.runner.ClockStub in project cucumber-jvm by cucumber.

the class JsonParallelRuntimeTest method testMultipleFeatures.

@Test
void testMultipleFeatures() {
    ByteArrayOutputStream parallel = new ByteArrayOutputStream();
    Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(3).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/JsonPrettyFormatterTest.feature")).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/FormatterInParallel.feature")).build()).withAdditionalPlugins(new JsonFormatter(parallel)).withEventBus(new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID)).build().run();
    ByteArrayOutputStream serial = new ByteArrayOutputStream();
    Runtime.builder().withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(1).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/JsonPrettyFormatterTest.feature")).addFeature(FeatureWithLines.parse("src/test/resources/io/cucumber/core/plugin/FormatterInParallel.feature")).build()).withAdditionalPlugins(new JsonFormatter(serial)).withEventBus(new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID)).build().run();
    assertThat(parallel.toString(), sameJSONAs(serial.toString()).allowingAnyArrayOrdering());
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) ClockStub(io.cucumber.core.runner.ClockStub) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

ClockStub (io.cucumber.core.runner.ClockStub)3 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Test (org.junit.jupiter.api.Test)3 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)2 EventBus (io.cucumber.core.eventbus.EventBus)1 PluginOption (io.cucumber.core.options.PluginOption)1 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)1 Result (io.cucumber.plugin.event.Result)1 TestCase (io.cucumber.plugin.event.TestCase)1 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 UUID (java.util.UUID)1