java - 无法使用 Maven 运行测试来运行我的项目
问题描述
我正在尝试运行我的测试,但是我遇到了一个问题,即当我运行以下命令时我无法运行我的测试:
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
这是我的测试类的一个例子: --------------------EDIT-------------------- ----------------------
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", "*******"}
};
}
}
解决方案
从文档:
例如,纯元数据(打包值为 pom)的项目仅将目标绑定到安装和部署阶段(有关某些打包类型的目标到构建阶段绑定的完整列表,请参阅生命周期参考)。
如您所见,只有安装和部署阶段(不是测试)对pom
打包项目有效。
Java 代码不应该在那里,因为pom
项目应该是纯粹的元数据。
推荐阅读
- php - 列出目录及其子目录中的所有 .csv 文件 uisng PHP
- linux - 在 MX150 上安装 tensorflow-gpu 时出错
- ios - iOS Swift:范围数组
- android - 在 Android Studio 中打开第二个 Activity 错误
- angular - 设置伪元素的 z-index
- html - css:更改子 div 的背景颜色,但不更改父 div
- qt - 产生真/假以控制可见性的复杂逻辑
- apache-kafka - 没有 zkNodes 的 Spring Cloud Kafka binder
- c# - 读取大文本文件的前 n 个字符 - C#
- mysql - MySQL 将日期时间记录从 GMT+7 更新为 UTC