如何让 JBehave 在 Maven 中运行时包含测试依赖项 jar?
我有一个足够简单的项目,我正在尝试使用 JBehave 核心进行测试,并以 maven-kosher 方式进行操作(即在 src/main 下进行生产,在 src/test 下进行测试,在添加的情况下进行集成测试) src/it/{java,resources} 的路径,以及测试范围内的测试依赖项)。让这一切一起运行似乎比应有的要困难得多。
我的情况有点不同,因为我的代码位于 src/it/java 中,资源位于 src/it/resources 中。在 Maven 中配置这些内容后,Eclipse 可以正常运行故事 - 问题出在 Maven 上。
目前我的问题是它在运行时看不到mockito(或其他测试依赖项)(mvn -X)。即使编辑工作示例并添加测试依赖项也不包含它。
我已经能够通过将我的测试依赖项粘贴到插件 xml blob 中来使其工作,但显然我不想像那样重复自己。
构建文件的相关部分(没有手动指定的依赖项 hack)是:
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</testResource>
<testResource>
<directory>src/it/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</testResource>
</testResources>
...
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<executions>
<execution>
<id>embeddable-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/*Story.java</include>
</includes>
<ignoreFailureInStories>false</ignoreFailureInStories>
<ignoreFailureInView>false</ignoreFailureInView>
<scope>test</scope>
<testSourceDirectory>src/it/java</testSourceDirectory>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
想法?
I've got a simple-enough project that I'm trying to test with JBehave core, and doing things in a maven-kosher fashion (that is production under src/main, test under src/test, integration testing stuff under an added path of src/it/{java,resources}, and test dependencies scoped with test). Getting this all running together seems rather harder than it should be.
My case is a little different because my code is in src/it/java, and resources in src/it/resources. Having configured those in maven, Eclipse runs the stories just fine - the problem is with Maven.
Currently my problem is that it doesn't see mockito (or other test dependencies) when running (mvn -X). Even editing a working example and adding a test dependency doesn't include it.
I've been able to bodge it into working by sticking my test dependencies within the plugin xml blob, but obviously I don't want to repeat myself like that.
The relevant parts of the build file (without the manually specified dependency hack) are:
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</testResource>
<testResource>
<directory>src/it/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*</include>
</includes>
</testResource>
</testResources>
...
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<executions>
<execution>
<id>embeddable-stories</id>
<phase>integration-test</phase>
<configuration>
<includes>
<include>**/*Story.java</include>
</includes>
<ignoreFailureInStories>false</ignoreFailureInStories>
<ignoreFailureInView>false</ignoreFailureInView>
<scope>test</scope>
<testSourceDirectory>src/it/java</testSourceDirectory>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>
</executions>
</plugin>
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该插件的属性
scope
默认为compile
,我想你应该将其更改为test
。请参阅文档。另外,这里有一个很好的观点为什么
compile
是由默认。The plugin has property
scope
which defaults tocompile
, I suppose you should to change it totest
. Consult with the documentation.Also, here is good point why
compile
is by default.根据jbehave maven插件文档,
您是否也面临同样的问题?
According to jbehave maven plugin documentation,
Could you be facing the same issue?