【问题标题】:How to get JBehave to include test dependency jars when running in Maven?在 Maven 中运行时如何让 JBehave 包含测试依赖项 jar?
【发布时间】:2011-05-05 20:49:51
【问题描述】:

我有一个足够简单的项目,我正在尝试使用 JBehave 核心进行测试,并以 maven-kosher 方式做事(即在 src/main 下进行生产,在 src/test 下进行测试,集成测试的东西在 src/it/{java,resources} 的添加路径下,以及 test 范围内的测试依赖项)。让这一切一起运行似乎比应有的困难。

我的情况有点不同,因为我的代码在 src/it/java 中,而资源在 src/it/resources 中。在 maven 中配置好之后,Eclipse 就可以正常运行这些故事了 - 问题出在 Maven 上。

目前我的问题是它在运行 (mvn -X) 时看不到 mockito(或其他测试依赖项)。即使编辑一个工作示例并添加一个测试依赖项也不包括它。

我已经能够通过将我的测试依赖项粘贴在插件 xml blob 中来使其正常工作,但显然我不想这样重复自己。

构建文件的相关部分(没有手动指定的依赖破解)是:

<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>

想法?

【问题讨论】:

    标签: java maven bdd jbehave


    【解决方案1】:

    插件有属性scope,默认为compile,我想你应该把它改成test。咨询documentation

    另外,here is good point 为什么默认是compile

    【讨论】:

    • 我喜欢将它保存在 src/main 中的观点。我尝试了&lt;scope&gt;test&lt;/scope&gt;,但 Maven 似乎仍然忽略了它。 &lt;scope&gt; 元素是否属于 &lt;dependency&gt; 元素?它似乎没有让 Maven 让 jBehave 看起来在正确的位置。
    • @MichaelOsofsky 这个&lt;scope&gt; 也是插件配置的一部分。
    • 感谢@kan,看起来&lt;scope&gt; 属于&lt;plugin&gt;&lt;configuration&gt; 元素。谢谢!
    • 我在将 JBehave 保存在 src/main 而不是 src/test 时遇到了一个问题。见stackoverflow.com/questions/27629791/…
    【解决方案2】:

    根据jbehave maven插件documentation

    使用 JBehave Maven 插件时, 并取决于您的 POM 的其余部分 配置,您可能需要添加 Apache log4j 作为插件依赖(作为 反对项目依赖)如果 你发现它无法加载 它的类

    你会遇到同样的问题吗?

    【讨论】:

    • 嗯,这就是我所说的“将我的测试依赖项粘贴在插件 xml blob 中”的意思,但我认为这不是一个好的解决方案 - 从它的外观来看,我需要在那里复制我所有的测试依赖项。也许我会在邮件列表中询问并在此处报告任何发现。
    • @Dave LeBlanc。根据文档,only log4j 是必需的。我想你的情况不止于此
    • @DaveLeBlanc 你得到答案了吗?
    猜你喜欢
    • 2011-10-23
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 2015-06-27
    • 2011-12-06
    • 2010-12-16
    相关资源
    最近更新 更多