对于jbehave-的JUnit亚军添加@RunWith打破JBehave建立使用Maven(Add

2019-10-21 11:12发布

我使用JBehave我的Maven构建这也是我在Eclipse中开发,有时运行我的单元测试在Eclipse中的JUnit运行。 我发现jbehave-的JUnit亚军可以很好地用于美化的JUnit运行的JBehave的故事。 然而,增加jbehave-的JUnit亚军似乎已经打破了我的Maven构建。

结果mvn clean install在安装后https://github.com/codecentric/jbehave-junit-runner :

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[28,23] error: package org.junit.runner does not exist
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[42,1] error: cannot find symbol
[ERROR]   symbol: class RunWith
/Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[28,23] error: package org.junit.runner does not exist
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[42,1] error: cannot find symbol
[ERROR]   symbol: class RunWith
/Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[50,28] error: cannot access Runner
[INFO] 5 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.043 s
[INFO] Finished at: 2014-12-23T15:38:39-08:00
[INFO] Final Memory: 14M/156M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project followerdownloader-frontend: Compilation failure: Compilation failure:
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[28,23] error: package org.junit.runner does not exist
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[42,1] error: cannot find symbol
[ERROR] symbol: class RunWith
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[28,23] error: package org.junit.runner does not exist
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[42,1] error: cannot find symbol
[ERROR] symbol: class RunWith
[ERROR] /Users/mosofsky/Developer/FollowerDownloader/followerdownloader-frontend/src/main/java/com/netbase/followerdownloader/FollowerDownloaderStories.java:[50,28] error: cannot access Runner
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

这是关于https://github.com/codecentric/jbehave-junit-runner ,打破我的体型?

Answer 1:

该问题的解决办法是通过从在pom.xml文件中的junit测试元件拓宽的junit的范围:

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <!-- <scope>test</scope> -->     <!-- SOLUTION: COMMENTED OUT THIS LINE -->
</dependency>

我觉得我一头栽进JBehave和行为驱动开发(BDD)的一个悖论:

  • 在一方面,BDD是不是测试(见http://jbehave.org/reference/stable/examples-philosophy.html )。
  • 在另一方面,对于BDD,工具https://github.com/codecentric/jbehave-junit-runner ,依赖于@RunWith注释这是一个测试框架,具体org.junit.runner.RunWith。

我担心我的解决方案可能对我的生产代码的后果,如果我不再限制的junit范围的Maven的标准测试目录 。

然而,我的解决方案没有解决原来的问题。



文章来源: Adding @RunWith for jbehave-junit-runner breaks JBehave build using Maven