Coder Social home page Coder Social logo

Comments (13)

dschneller avatar dschneller commented on June 12, 2024

Yes, please provide the test class you are using that exhibits this problem. I have an idea, but would like to verify.

from jbehave-junit-runner.

ManuelAbril avatar ManuelAbril commented on June 12, 2024

Here you are my class. I hope there is my problem :)

package org.jbehave.business;

import java.io.File;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.jbehave.business.generic.GenericConfiguration;
import org.jbehave.business.generic.GenericFormat;
import org.jbehave.business.generic.GenericStep;
import org.jbehave.business.utils.PropertyConstants;
import org.jbehave.business.utils.StringUtil;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.embedder.Embedder;
import org.jbehave.core.io.LoadFromRelativeFile;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.model.ExamplesTableFactory;
import org.jbehave.core.parsers.RegexStoryParser;
import org.jbehave.core.reporters.CrossReference;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.CandidateSteps;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.jbehave.core.steps.spring.SpringApplicationContextFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;

import de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner;

@RunWith(JUnitReportingRunner.class)
public class MyStories extends JUnitStories {

    private static Configuration configuration = null;
    private static GenericConfiguration coreConfiguration = null;
    private static CrossReference xref = null;
    @SuppressWarnings("rawtypes")
    private static List steps = null;

    @SuppressWarnings({"rawtypes", "unchecked" })
    public MyStories() {
        try {
            xref = new CrossReference().withJsonOnly().withOutputAfterEachStory(true).excludingStoriesWithNoExecutedScenarios(true);
            //ApplicationContext appContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
            String path = "org.jbehave.business".replaceAll("\\.", "/");
            ApplicationContext appContext = new SpringApplicationContextFactory(path + "/applicationContext.xml").createApplicationContext();
            coreConfiguration = appContext.getBean("config", GenericConfiguration.class);
            Map beanMap = appContext.getBeansOfType(GenericStep.class);
            steps = new ArrayList(beanMap.values());
            Embedder processor = new Embedder();
            processor.embedderControls().doGenerateViewAfterStories(true);
            processor.embedderControls().doIgnoreFailureInStories(true);
            useEmbedder(processor);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    /**
     * set the configuration of JBehave.
     * 
     * @return Configuration for JBehave
     */
    @Override
    public Configuration configuration() {
        if (configuration == null) {
            StoryReporterBuilder reporterBuilder = new StoryReporterBuilder();
            // Selected output format
            reporterBuilder.withFormats(GenericFormat.getFormatArray(coreConfiguration.getStringArray(PropertyConstants.REPORT_FORMAT)));
            reporterBuilder.withFailureTrace(true);
            reporterBuilder.withFailureTraceCompression(false);
            reporterBuilder.withCrossReference(xref);
            configuration = new MostUsefulConfiguration();
            File codeLocation = new File(coreConfiguration.getString(PropertyConstants.STORY_PATH));
            try {
                configuration.useStoryLoader(new LoadFromRelativeFile(codeLocation.toURI().toURL()));
                configuration.useStoryParser(new RegexStoryParser(new ExamplesTableFactory(new LoadFromRelativeFile(codeLocation.toURI().toURL()))));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            configuration.useStoryReporterBuilder(reporterBuilder);
            configuration.useStepMonitor(xref.getStepMonitor());
        }
        return configuration;
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<CandidateSteps> candidateSteps() {
        InstanceStepsFactory stepFactory = new InstanceStepsFactory(configuration(), steps);
        return stepFactory.createCandidateSteps();
    }

    /**
     * load the story files from a path.
     * 
     * @return a list of paths for stories
     */
    @Override
    protected List<String> storyPaths() {
        String separator = StringUtil.defaultIfEmpty(coreConfiguration.getString(PropertyConstants.STORY_SEPARATOR), ",");
        List<String> includes = StringUtil.toList(coreConfiguration.getString(PropertyConstants.STORY_INLCUDE), separator);
        List<String> excludes = StringUtil.toList(coreConfiguration.getString(PropertyConstants.STORY_EXLUDE), separator);
        List<String> storyPaths = new StoryFinder().findPaths(coreConfiguration.getString(PropertyConstants.STORY_PATH), includes, excludes);
        return storyPaths;
    }

    @Override
    @Test
    public void run() {
        try {
            super.run();
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }
}

from jbehave-junit-runner.

AndreasEK avatar AndreasEK commented on June 12, 2024

Hi,

which version of the jbehave-junit-runner are you using? If you are using 1.0.0 please try out the 1.0.1-SNAPSHOT as there's a bugfix contained for using CrossReferences (Issue #8)

Andreas

from jbehave-junit-runner.

dschneller avatar dschneller commented on June 12, 2024

That's what I wanted to check :)

from jbehave-junit-runner.

ManuelAbril avatar ManuelAbril commented on June 12, 2024

Hi guys,

I downloaded the last SNAPSHOT (jbehave-junit-runner-1.0.1-20120525.215233-12) and I even commented the code of the CrossReferences but the problems is still there. I realised that the following line is failing in the JUnitReportingRunner: candidateSteps = embedder.stepsFactory().createCandidateSteps();

It seems that the embedder.stepsFactory() get a NULL.

from jbehave-junit-runner.

AndreasEK avatar AndreasEK commented on June 12, 2024

Hi Manuel,

thanks for the debugging. I'll try to reproduce the problem with your information.

Andreas

from jbehave-junit-runner.

AndreasEK avatar AndreasEK commented on June 12, 2024

Hi,

back from further evaluation :) It seems to me, that you're only extending JUnitStories half-way. You've chosen to override candidateSteps(), but not stepsFactory(). Also you've your own implementation of the run method. May I ask, why you chose to implement your class like this?

That said, I've changed the implementation to use the stepsFactory from the Embedder, which has a fallback to a ProvidedStepsFactory, if none was given. Hope that fixes the issue for you :)

from jbehave-junit-runner.

AndreasEK avatar AndreasEK commented on June 12, 2024

Hi, can you please check again with the latest SNAPSHOT? Thanks, Andreas

from jbehave-junit-runner.

ManuelAbril avatar ManuelAbril commented on June 12, 2024

Thanks @AndreasEK, I will check if the latest SNAPSHOT solves the issue. In addition, "answering" your question...

It seems to me, that you're only extending JUnitStories half-way. You've chosen to override candidateSteps(), but not stepsFactory(). Also you've your own implementation of the run method. May I ask, why you chose to implement your class like this?

I home working with this class right now but it is not developed by me, so I do not have any asnwer. Annyway, I would appreciate if you give me some advice on it, so please write me via email, [email protected], or just share it with all of us over here.

from jbehave-junit-runner.

ManuelAbril avatar ManuelAbril commented on June 12, 2024

Thank you again, @AndreasEK. It works perfectly. Great job ;)

from jbehave-junit-runner.

AndreasEK avatar AndreasEK commented on June 12, 2024

great. I see a release of version 1.0.1 coming. Feedback on your class either here or on our blog (generalized).

from jbehave-junit-runner.

ManuelAbril avatar ManuelAbril commented on June 12, 2024

Cool. Let me know where the feedback is ready. Is it your blog? http://blog.codecentric.de/en/

from jbehave-junit-runner.

AndreasEK avatar AndreasEK commented on June 12, 2024

Yep, that's our blog. FYI: I just released 1.0.1 :) Have fun, Andreas

from jbehave-junit-runner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.