Integration of jbehave with jenkins

北慕城南 提交于 2019-12-05 21:33:51

So I'm assuming you have JBehave integrated with Maven, correct? The simple build environment can be set up as follows:

  1. Go to Jenkins and add a new job of type "Build a maven2/3 project"
  2. Configure your project to check out your from whatever source repository you use.
  3. Configure the build phase of the project to run whatever Maven goal you need ("install" will probably work)
  4. Hit save and you have a working project that will execute exactly as it would from a command line.

If you want to see the JBehave test output rendered nicely in Jenkins you should also follow these instructions to configure the Jenkins/XUnit plugin: http://jbehave.org/reference/stable/hudson-plugin.html

You will also need to make sure your project is configured to use the XML Output format in your StoryReporterBuilder to make use of the plugin (not mentioned in the instructions above).

You can visit the following for details:

http://jbehave.org/reference/stable/hudson-plugin.html

Per your comments, you want to specify the stories to run via Jenkins when using the Maven plugin. Here is one way:

Create a subclass of StoryFinder and set it as the storyFinderClass property in your Maven configuration. In the Jenkins commandline launcher, you can pass in stories as a -D system property which can then be read from your StoryFinder.

Commandline

mvn ... -Dcom.sarang.stories="foo.story,bar.story"

Maven

<plugin>
    <groupId>org.jbehave</groupId>
    <artifactId>jbehave-maven-plugin</artifactId>
    <version>[version]</version>
    <executions>
        <execution>
            <id>run-stories-as-embeddables</id>
            <phase>integration-test</phase>
            <configuration>
                ...
                <systemProperties>
                    <property>
                      <name>com.sarang.stories</name>
                      <value>${com.sarang.stories}</value>
                    </property>
                </systemProperties>
                <storyFinderClass>com.sarang.MyStoryFinder</storyFinderClass>
            </configuration>
            <goals>
                <goal>run-stories-as-embeddables</goal>
                ...
            </goals>
        </execution>
    </executions>
</plugin>

StoryFinder

package com.sarang;

import org.jbehave.core.io.StoryFinder;
import java.util.*;

public class MyStoryFinder extends StoryFinder {
    @Override
    protected List<String> scan(String basedir, List<String> includes,
            List<String> excludes) {
        //List<String> defaultStories = super.scan(basedir, includes, excludes);
        String myStories = System.getProperty("com.sarang.stories");
        return Arrays.asList(myStories.split(","));
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!