jbehave / jbehave-core

BSD 3-Clause "New" or "Revised" License
31 stars 17 forks source link

Test #57

Closed mdzhigarov closed 1 year ago

mdzhigarov commented 1 year ago

This is probably a user misconfiguration on my side but I'd appreciate if you could help me resolve it.

I have a couple of jUnit test classes, each of them containing a single @Test method that instantiates a jBehave JupiterStories and manually invokes its run() method (see below example).

I'm using IntelliJ as IDE to develop and run those tests. The problem is the following:

  1. I run one of the tests that contains a story called "Generic Allocation Task E2e". The story fails due to production code bug and hence - the jUnit test fails.
  2. Without cleaning up the target/jbehave folder I run another test that contains a story called "Generic Allocation Task Already Executed". The story succeeds, however, the jUnit test itself fails because the story from 1. is still in the target/jbehave/view/report.html report and jBehave seems to report a failure.

image image

How do I fix this? It's very misleading that my GenericAllocationTaskAlreadyExecutedStoryTest test is shown as failing in IntelliJ when in fact it's another test from an older execution that caused it to fail. Is there a configuration to fix that?

public class GenericAllocationTaskAlreadyExecutedStoryTest extends RequestBaseTest {

    @Test
    public void runStory() {
        new GenericAllocationTaskAlreadyExecutedStory().run();
    }

    public class GenericAllocationTaskAlreadyExecutedStory extends JupiterStories {
        @Override
        public Configuration configuration() {
            Class<? extends Embeddable> embeddableClass = this.getClass();
            Properties viewResources = new Properties();
            viewResources.put("decorateNonHtml", "true");
            // Start from default ParameterConverters instance
            ParameterConverters parameterConverters = new ParameterConverters();
            // factory to allow parameter conversion and loading from external
            // resources (used by StoryParser too)

            return new MostUsefulConfiguration()
                    .useStoryControls(new StoryControls().doDryRun(false).doSkipScenariosAfterFailure(false))
                    .useStoryLoader(new LoadFromClasspath(embeddableClass))
                    .useStoryPathResolver(new UnderscoredCamelCaseResolver())
                    .useStoryReporterBuilder(
                            new StoryReporterBuilder()
                                    .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass))
                                    .withSurefireReporter(new SurefireReporter(embeddableClass))
                                    .withDefaultFormats().withPathResolver(new ResolveToPackagedName())
                                    .withViewResources(viewResources).withFormats(CONSOLE, HTML)
                                    .withFailureTrace(true)
                                    .withFailureTraceCompression(true))
                    .useParameterConverters(parameterConverters);
        }

        @Override
        public InjectableStepsFactory stepsFactory() {
            return new InstanceStepsFactory(configuration(), getSteps());
        }

        private List<Object> getSteps() {
            StepContext context = new StepContext(
                    GenericAllocationTaskAlreadyExecutedStoryTest.this);
            return Arrays.asList(
                    new ComputeAllocationSteps(context),
                    new NetworkAllocationSteps(context),
                    new FlavorAllocationSteps(context),
                    new GenericAllocationTaskSteps(context));
        }

        @Override
        public List<String> storyPaths() {
            return new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()),
                    String.format("**/%s", "generic_allocation_task_already_executed.story"), "");
        }

        @Override
        public Embedder injectedEmbedder() {
            Embedder embedder = super.injectedEmbedder();
            embedder.useMetaFilters(Arrays.asList("-Ignored"));
            return embedder;
        }
    }
}

Exception at the end of the test:

Generating reports view to '***\target\jbehave' using formats '[stats, console, html]' and view properties '{decorateNonHtml=true}'
Reports view generated with 3 stories (of which 0 pending) containing 11 scenarios (of which 0 pending)
12:12:10.731+0200  INFO [main] ***.GenericAllocationTaskAlreadyExecutedStoryTest.log:454 - ---> ENDING test: GenericAllocationTaskAlreadyExecutedStoryTest.runStory

org.jbehave.core.embedder.Embedder$RunningStoriesFailed: Failures in running stories: ReportsCount[scenarios=11,scenariosExcluded=0,scenariosFailed=9,scenariosPending=0,stepsFailed=9,stories=3,storiesExcluded=0,storiesPending=0]

    at org.jbehave.core.embedder.Embedder$ThrowingRunningStoriesFailed.handleFailures(Embedder.java:546)
    at org.jbehave.core.embedder.Embedder.handleFailures(Embedder.java:253)
    at org.jbehave.core.embedder.Embedder.generateReportsView(Embedder.java:281)
    at org.jbehave.core.embedder.Embedder.generateReportsView(Embedder.java:262)
    at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:222)
    at org.jbehave.core.junit.JupiterStories.run(JupiterStories.java:22)
    at com.***.GenericAllocationTaskAlreadyExecutedStoryTest.runStory(GenericAllocationTaskAlreadyExecutedStoryTest.java:50)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:54)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
mdzhigarov commented 1 year ago

I found the configuration I need to fix this: embedder.embedderControls().doIgnoreFailureInView(true);

Closing...