我需要将字符串值(jbehave 故事文件名)从 cmd 传递给 .java 文件。像这样的东西:
mvn verify -PMyTests -DstoryName=purchasing.story
以这种方式在java中使用:
System.out.println(storyName);
我的设置:
现在测试由
mvn verify -PMyTests
pom.xml文件结构:
...
<dependencies>
...
</dependencies>
<build>
...
<build>
<profiles>
<profile>
<id>MyTests</id>
<build>
<plugins>
...
</plugins>
</build>
</profile>
MyStories.java:
public class MyStories extends JUnitStories {
...
@Override
protected List<String> storyPaths() {
return new StoryFinder()
.findPaths(codeLocationFromClass(embeddableClass).getFile(), asList(
"**/purchasing.story"
), null);
}
}
尝试了这些主题:有没有办法在编译期间在 java 类中使用 maven 属性,如何从 maven 传递 java 代码参数进行测试,但没有结果。简单明了的教程、搜索提示或带有示例的文档表示赞赏。
PS找到了足够简单且适合我的解决方案:http: //syntx.co/languages-frameworks/how-to-pass-parameters-to-the-junit-tests-from-the-maven-surefire-plugin/
评论中提供的解决方案(我“复制”的主题)比这个更复杂,所以新手更容易犯错实施它