问题
My RunCukeTest class looks like:
package runsupport;
import ....
@RunWith(Cucumber.class)
@CucumberOptions(
monochrome = true,
features = "classpath:features",
plugin = {"pretty", "html:target/cucumber-html-report", "json:target/cucumber.json"},
glue = { "classpath:steps", "classpath:runsupport" },
tags = {"@search"}
)
public class RunCukesTest{
}
How do I convert this to mvn test -Dcucumber.options="" format so that I can run it from the Goals line of a Maven Build run configuration? I want to be able to change the tags on the run configuration rather than having to edit the RunCukeTest class each time.
回答1:
The answer turned out to be:
clean test -Dcucumber.options="--tags @search --monochrome --plugin pretty:STDOUT --plugin html:target/cucumber-html-report --plugin json:target/cucumber.json --glue steps --glue runsupport classpath:features"
Note that since I have two glue paths that I needed two --glue statements. Also note that only the package name of the two -glue paths were specified.
Further note that STDOUT needed to be specified on --plugin pretty:STDOUT.
Finally note that the feature keyword was dropped completely. The path specified at the end (without a keyword) tells cucumber-jvm where to find the feature files.
If you get any of this wrong cucumber-jvm gives you cryptic error messages. I thought that I would post this for the next person to save him or her an hour or two.
BTW, to get a Maven Build configuration in Eclipse, click on Run > Run Configurations... On the left pane double-click Maven Build. A default Maven Build configuration is created. Give it a good name and on the Goals line paste your clean test -Dcucumber.options line. It wouldn't hurt to click on the JRE tab and make sure that the correct JDK is being used. Back on the Main tab, press Apply, press Run. It completely overrides the @CucumberOptions line in your RunCukesTest (or whatever you named it) class. It is a lot easier to run tests this way and you aren't confusing git with unnecessary local file edits.
来源:https://stackoverflow.com/questions/36193307/how-to-translate-maven-cucumber-jvm-junit-cucumberoptions-to-eclipse-run-co