【发布时间】:2016-11-17 20:07:23
【问题描述】:
这是我的文件:
Pom 父母:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group</groupId>
<artifactId>my.artifact.pom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>my.artifact.ws</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<properties>
<!-- test -->
<maven.test.failure.ignore>false</maven.test.failure.ignore>
</properties>
//lot of dependencies...
<!-- PROFILES -->
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<unit-tests.skip>false</unit-tests.skip>
<integration-tests.skip>true</integration-tests.skip>
</properties>
</profile>
<profile>
<id>integration</id>
<modules>
<module>my-module-integration-test</module>
</modules>
<properties>
<unit-tests.skip>true</unit-tests.skip>
<integration-tests.skip>false</integration-tests.skip>
</properties>
</profile>
</profiles>
<!-- PLUGIN -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>${encoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
模块-ws pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>my.artifact.ws</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>my.group</groupId>
<artifactId>my.artifact.pom</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
//lot of dependencies...
</project>
集成测试 pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>my.artifact.integration.test</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>my.group</groupId>
<artifactId>my.artifact.pom</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<unit-tests.skip>false</unit-tests.skip>
<integration-tests.skip>true</integration-tests.skip>
</properties>
<dependencies>
<dependency>
<groupId>my.group</groupId>
<artifactId>my.artifact.ws</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我的文件夹结构:
my-module
|-- my-module-integration-test
| `-- src
| `-- test
| `-- java
| `-- my
| `-- module
| `-- ws
| `-- rest
| `-- MyTest
`-- my-module-ws
`-- src
`-- main
`-- java
`-- my
`-- module
`-- Application
当我运行mvn clean install -P integration 时,我会收到消息:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project mp-schedule-integration-test: Compilation failure: Compilation failure:
[ERROR] /Users/me/dev/my-module/my-module-integration-test/src/test/java/my/module/ws/rest/MyTest.java:[3,28] cannot find symbol
[ERROR] symbol: class Application
[ERROR] location: package my.module
如果我将 Application 类放在 my-module-integration-test 的测试结构中,它可以工作(Go Horse)
有人可以帮我吗?
Ps.: os 模块和项目的名称可能是错误的,只是为了隐藏原始名称。
【问题讨论】:
-
你确定你对包含Application类的模块有正确的依赖吗?
-
@Lucas 你用的是什么 maven 版本?我无法用 maven 3.x 重现它
-
您使用的是
<module>my.artifact.ws</module>,但在后面的树中,磁盘上的文件夹称为my-module-ws(带有破折号,而不是圆点)。它是哪一个?请发minimal reproducible example,否则无法提供帮助。可能是该类受包保护而您无法访问它吗?您还需要发布Application,可能还需要发布MyTest。这里有太多的未知数。 -
但底线是这应该可以工作,所以问题出在你没有展示的东西上。假设你是从多模块项目的父 POM 构建的,正如你一直应该做的那样,我的钱是
Application而不是public。或者某处有错字,因为您发布的 POM 不可能是您真正的 POM,因为它们甚至没有有效的 XML 语法。 -
嗨卢卡斯。我无法使用问题中提供的信息重现您的问题。但也许这个链接会对你有所帮助:github.com/StefanHeimberg/…。我为我们公司的一些讨论创建了带有单元/集成和系统测试的多项目设置的 github 存储库
标签: java maven testing integration-testing