Coder Social home page Coder Social logo

Comments (6)

Miuler avatar Miuler commented on June 12, 2024 1

Hi people, this is other example :)

package com.miuler.service.features;

import static java.util.Arrays.asList;
import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;

import java.util.List;

import org.jbehave.core.annotations.Configure;
import org.jbehave.core.annotations.UsingEmbedder;
import org.jbehave.core.annotations.UsingSteps;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.ScanningStepsFactory;
import org.jbehave.core.steps.spring.SpringApplicationContextFactory;
import org.jbehave.core.steps.spring.SpringStepsFactory;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestContextManager;

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


@RunWith(JUnitReportingRunner.class)
@ContextConfiguration(locations = {
        // DAO
        "/com/miuler/dao/config/spring-config.xml",

        // Service
        "/com/miuler/service/config/spring-service.xml"
})
public class RunFeaturesTest extends JUnitStories {

    @Autowired
    ApplicationContext applicationContext;

    private TestContextManager testContextManager;

    public RunFeatures867Test() {
        JUnitReportingRunner.recommendedControls(configuredEmbedder());
    }


    @Override
    protected List<String> storyPaths() {
        String searchInDirectory = codeLocationFromClass(getClass()).getFile();
        return new StoryFinder().findPaths(searchInDirectory, asList("**/*.story"), null);
    }

    @Override
    public Configuration configuration() {
        try {
            this.testContextManager = new TestContextManager(getClass());
            this.testContextManager.prepareTestInstance(this);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return new MostUsefulConfiguration()
                .useStoryLoader(new LoadFromClasspath(this.getClass()))
                .useStoryReporterBuilder(new StoryReporterBuilder().withFormats(Format.CONSOLE, Format.HTML))
                ;
    }

    @Override
    public InjectableStepsFactory stepsFactory() {
        return new SpringStepsFactory(configuration(), applicationContext);
    }
}

from jbehave-junit-runner.

britter avatar britter commented on June 12, 2024

You can only use one test runner per test, so it's not possible to annotate your test with both test runners. Googling "junit use multiple runners" gave me this result: http://www.blog.project13.pl/index.php/coding/1077/runwith-junit4-with-both-springjunit4classrunner-and-parameterized/
Maybe this is what you're looking for?

from jbehave-junit-runner.

mstachniuk avatar mstachniuk commented on June 12, 2024

Based on link in comment I found a solution:

@ActiveProfiles("test-h2")
@RunWith(JUnitReportingRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext/test-applicationContext.xml"})
public abstract class AbstractConfigurationTest extends JUnitStories {

    private TestContextManager testContextManager;

    public AbstractConfigurationTest() {
        JUnitReportingRunner.recommandedControls(configuredEmbedder());
    }

    @Override
    public Configuration configuration() {
        this.testContextManager = new TestContextManager(getClass());
        try {
            this.testContextManager.prepareTestInstance(this);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
        return new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass()))
                .useStoryReporterBuilder(new StoryReporterBuilder().withFormats(Format.CONSOLE));
    }
}

from jbehave-junit-runner.

britter avatar britter commented on June 12, 2024

Nice that you figured that one out. Thanks for the example, it may help others looking for the same thing.

from jbehave-junit-runner.

max-polyakov avatar max-polyakov commented on June 12, 2024

I am confused about @RunWith(SpringJUnitReportingRunner.class) removal from jbehave-junit-runner jar.

README file in git;
https://github.com/schmidtl/jbehave-junit-runner
still contain the example below:

@RunWith(SpringJUnitReportingRunner.class)
@ContextConfiguration(locations = "classpath:spring-test.xml")
public class MyAcceptanceTests extends JUnitStories {
@Autowired
private WebDriverSteps lifecycleSteps;
...
}

from jbehave-junit-runner.

max-polyakov avatar max-polyakov commented on June 12, 2024

mstachniuk - Thank you uring for figuring this out! Kudos! One more thing should be done in order to enable autowiring in steps classes is override:
@OverRide
public InjectableStepsFactory stepsFactory() {

  ApplicationContext context = new SpringApplicationContextFactory("/properties/mps-steps.xml").createApplicationContext();
  return new SpringStepsFactory(configuration(), context);
}

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.