我正在尝试运行测试,但是遇到一个问题,当我运行以下命令时,我无法运行测试:
mvn clean test
项目中的每个模块都包含pom.xml
文件,该文件仅包含与该模块相关的依赖项。
主要pom.xml(反应堆)是运行测试并控制项目的文件,这是其内容:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hackeruso</groupId>
<artifactId>neo</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<modules>
<module>automation-ui</module>
<module>automation-api</module>
<module>morpheus</module>
</modules>
<name>neo</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<aspectj.version>1.8.10</aspectj.version>
<testng.version>7.3.0</testng.version>
</properties>
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.13.6</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
当我运行命令mvn test
时,我收到以下消息:
No tests to run.
src/test/java/com/hackeruso/automation/ui/LoginTest
这是我的测试课程的示例: --------------------编辑-------------------------- -----------------
package com.hackeruso.automation.ui;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class LoginTest extends BaseTest{
@Test(dataProvider = "userDetailsProvider")
public void loginTest(String username, String password){
signIn(username, password);
}
@DataProvider(name = "userDetailsProvider")
public Object[][] userDetailsProvider(){
return new Object[][] {
{"erezn@hackeruso.com", "*******"}
};
}
}
答案 0 :(得分:2)
例如,一个纯粹是元数据的项目(打包值为 pom)仅将目标绑定到安装和部署阶段(对于完整 某些包装类型的目标到构建阶段绑定的列表, 请参阅《生命周期参考》。
如您所见,对于pom
打包的项目,只有安装和部署阶段(不是测试阶段)有效。
Java代码不应存在,因为pom
项目应纯粹是元数据。
答案 1 :(得分:1)
父项目的包装为<packaging>pom</packaging>
。这意味着这是一个元项目,不应包含任何源代码。
您需要做的是将测试移至任何现有模块中或为这些测试创建一个新模块。通过查看测试的程序包结构,我猜您的情况应该是automation-ui
。
然后使用以下命令从所有模块运行测试
mvn test -am
-am
将构成所有子模块的地方。
如果要为单个模块运行测试,请使用
mvn test -pl <submodule-name>
答案 2 :(得分:0)
因此,最终我要做的是创建另一个模块进行测试,并且主项目模块将仅包含@Yasin建议的元数据,我还从主项目模块中删除了'src'包,仅保留了pom.xml文件。它将管理其他模块(反应堆)。 现在一切都按预期进行。
谢谢!