简体   繁体   English

Maven不通过Eclipse在多模块项目中运行测试

[英]Maven not running tests through eclipse in multimodule project

I have a simple multimodule maven project structure as below : 我有一个简单的多模块Maven项目结构,如下所示:

main-project : 
   -test-child-one : 
   -test-child-three : 
   -test-child-two : 

When I run mvn test through eclipse from inside parent project, no tests are run. 当我从父项目内部通过Eclipse运行mvn test ,没有运行测试。

I have also tried running mvn test from inside one of child projects - test-child-one , but tests are not run . 我也尝试从子项目之一test-child-one内部运行mvn test ,但是测试未运行。

It always shows - 它总是显示-

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

The pom for parent and child are below : 父母和孩子的pom如下:

parent 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>

child pom : 儿童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>

Is there anything I am missing here ? 我在这里想念什么吗?

Please help. 请帮忙。

The convention over convention paradigm is important related to Maven that means you have a default directory layout and of course naming schemas. 约定范式的约定与Maven有关,这很重要,这意味着您具有默认的目录布局,当然还有命名模式。 This means you have to name your tests accordingly to those schemas . 这意味着您必须根据这些模式来命名测试。

To define unit tests you should name them like this: 要定义单元测试,您应该这样命名它们:

  • **/Test*.java ** /测试* .java
  • **/*Test.java ** / * Test.java
  • **/*Tests.java ** / * Tests.java
  • **/*TestCase.java ** / * TestCase.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM