【发布时间】:2018-04-02 08:29:59
【问题描述】:
我有一个简单的多模块 maven 项目结构如下:
main-project :
-test-child-one :
-test-child-three :
-test-child-two :
当我从父项目内部通过 eclipse 运行 mvn test 时,没有运行任何测试。
我还尝试从子项目之一 - test-child-one 中运行 mvn test,但没有运行测试。
它总是显示 -
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
父母和孩子的pom如下:
父 pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.atul.multimodule</groupId>
<artifactId>main-project</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>main-project</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>test-child-one</module>
<module>test-child-two</module>
<module>test-child-three</module>
</modules>
</project>
子 pom:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.atul.multimodule</groupId>
<artifactId>main-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.atul.multimodule</groupId>
<artifactId>test-child-one</artifactId>
<version>1.0-SNAPSHOT</version>
<name>test-child-one</name>
<url>http://maven.apache.org</url>
</project>
我在这里有什么遗漏吗?
请帮忙。
【问题讨论】:
-
按照约定将测试放入
src/test/java并将它们命名为*Test.java?您是否尝试过仅通过mvn clean test从根位置在纯命令行中运行? -
是的。它也不从命令行运行
-
你能通过 github 左右提供那个项目吗?否则很难看出问题出在哪里?
-
测试类的名称是 AppTestChildOne1.java,因此它没有被 maven 选中。将类名更改为 AppTest.java 效果很好
-
当然不会被拾取,因为它不遵循naming schema。所以你应该把它命名为
*Test.java等。