如何让 JBehave 在 Maven 中运行时包含测试依赖项 jar?

发布于 2024-11-05 02:01:08 字数 2000 浏览 1 评论 0原文

我有一个足够简单的项目,我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

勿忘初心 2024-11-12 02:01:08

该插件的属性 scope 默认为 compile,我想你应该将其更改为 test。请参阅文档

另外,这里有一个很好的观点为什么compile是由默认。

The plugin has property scope which defaults to compile, I suppose you should to change it to test. Consult with the documentation.

Also, here is good point why compile is by default.

甜味拾荒者 2024-11-12 02:01:08

根据jbehave maven插件文档

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

您是否也面临同样的问题?

According to jbehave maven plugin documentation,

When using the JBehave Maven Plugin,
and depending on the rest of your POM
configuration, you may need to add
Apache log4j as Plugin Dependency (as
opposed to the Project Dependency) if
you find that it's not able to load
its classes

Could you be facing the same issue?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文