首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用build-helper-maven-plugin和module跳过测试

使用build-helper-maven-plugin和module跳过测试
EN

Stack Overflow用户
提问于 2012-02-13 17:53:46
回答 3查看 1.9K关注 0票数 3

我将build-helper-maven-plugin用于具有非标准树文件夹的遗留项目。

我这样使用它:

代码语言:javascript
复制
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${basedir}/firstmodule/src</source>
                            <source>${basedir}/secondmodule/src</source>
                        </sources>
                    </configuration>
                </execution>
                <execution>
                    <id>add-test-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${basedir}/firstmodule/tests</source>
                            <source>${basedir}/secondmodule/tests</source>
                                                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

如果我在项目的根目录上启动mvn install,它可以正常工作,测试通过。

然而,这个项目是一个更大项目中的一个子模块。如果我在父项目的根文件夹中启动mvn install,maven不会执行测试。

它似乎起作用了,但保证不会检测到任何测试:

代码语言:javascript
复制
[INFO] Building MyLegacyProject
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\target
[INFO] [build-helper:add-source {execution: add-source}]
[INFO] Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\firstmodule\src added.
[INFO] Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\secondmodule\src added.
[INFO] [build-helper:add-test-source {execution: add-test-source}]
[INFO] Test Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\firstmodule\tests added.
[INFO] Test Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\secondmodule\tests added.
[debug] execute contextualize
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 40 resources
[INFO] Copying 40 resources
[WARNING] While downloading com.sun.xml:saaj-impl:1.3
  This artifact has been relocated to com.sun.xml.messaging.saaj:saaj-impl:1.3.


[WARNING] While downloading javax.xml:jaxb-api:2.1
  This artifact has been relocated to javax.xml.bind:jaxb-api:2.1.


[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 752 source files to C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\target\classes
[debug] execute contextualize
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 34 resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 15 source files to C:\DEV\perforce\1992\depot\MyLegacyProject\release\BUG_FIXING\MyLegacyProject\target\test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\DEV\perforce\1992\depot\MyLegacyProject\release\BUG_FIXING\MyLegacyProject\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.381 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

你知道怎么做吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-02-14 21:41:07

我找到了!

也有人遇到了同样的问题:https://stackoverflow.com/a/6925096/242658

然而,这真的很难理解。

它与build-helper-maven-plugin无关,我不知道为什么我在单模块模式下没有这个问题。

我使用了powermock和引入TestNG的powermock。使用testng,我的测试不会被surefire检测到。所以我不得不排除testng:

代码语言:javascript
复制
<dependency>
  <groupId>org.powermock</groupId>
  <artifactId>powermock-mockito-release-full</artifactId>
  <version>1.4.9</version>
  <classifier>full</classifier>
  <exclusions>
    <exclusion>
      <artifactId>powermock-module-testng</artifactId>
      <groupId>org.powermock</groupId>
    </exclusion>
  </exclusions>
</dependency>
票数 0
EN

Stack Overflow用户

发布于 2012-02-14 04:01:30

尝试以调试模式(-X)启动mvn,以查看surefire使用的属性对于您的树文件夹是否正确。

票数 0
EN

Stack Overflow用户

发布于 2012-02-14 17:34:14

你在使用maven3吗?${ basedir }只被Maven 3识别(并且被maven 2默默地忽略了:( )你如何理解basedir的用法?它是开始构建的POM的目录路径。因此,它要么是父项目目录的路径,要么是它的一个模块,这取决于您从何处启动构建。在第二种情况下,路径将是错误的。我想您希望项目的根目录的路径总是存在的吧?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9258485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档