不能 运行 使用 Maven 测试 运行 我的项目
cannot run tests using maven to run my projects
我正在尝试 运行 我的测试,但我遇到了一个问题,当我 运行 以下命令时我无法 运行 我的测试:
mvn clean test
我的项目包含 3 个模块(见附图):
项目中的每个模块都包含 pom.xml
文件,该文件仅包含与模块相关的依赖项。
主要pom.xml(reactor)是运行测试和控制项目的文件,这是它的内容:
<?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
这是我测试的例子class:
--------------------编辑------------------------ ------------------
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[][] {
{"user@mail.com", "*******"}
};
}
}
For example, a project that is purely metadata (packaging value is
pom) only binds goals to the install and deploy phases (for a complete
list of goal-to-build-phase bindings of some of the packaging types,
refer to the Lifecycle Reference).
如您所见,只有安装和部署阶段(不是测试)对 pom
打包项目有效。
Java 代码应该不存在,因为 pom
项目应该是纯元数据。
父项目的包装为<packaging>pom</packaging>
。这意味着这是一个 meta-project,不应包含任何源代码。
您需要做的是移动任何现有模块中的测试或为这些测试创建一个新模块。通过查看测试的包结构,我猜你的情况是 automation-ui
。
然后使用以下命令运行所有模块的测试
mvn test -am
其中 -am
将生成所有子模块。
如果要运行 测试单个模块,请使用
mvn test -pl <submodule-name>
所以最终我所做的是创建另一个用于测试的模块,主项目模块将仅包含@Yasin建议的元数据,我还从我的主项目模块中删除了 'src' 包,只留下一个pom.xml 将管理其他模块(反应器)的文件。
现在一切正常。
谢谢!
我正在尝试 运行 我的测试,但我遇到了一个问题,当我 运行 以下命令时我无法 运行 我的测试:
mvn clean test
我的项目包含 3 个模块(见附图):
项目中的每个模块都包含 pom.xml
文件,该文件仅包含与模块相关的依赖项。
主要pom.xml(reactor)是运行测试和控制项目的文件,这是它的内容:
<?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
这是我测试的例子class: --------------------编辑------------------------ ------------------
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[][] {
{"user@mail.com", "*******"}
};
}
}
For example, a project that is purely metadata (packaging value is pom) only binds goals to the install and deploy phases (for a complete list of goal-to-build-phase bindings of some of the packaging types, refer to the Lifecycle Reference).
如您所见,只有安装和部署阶段(不是测试)对 pom
打包项目有效。
Java 代码应该不存在,因为 pom
项目应该是纯元数据。
父项目的包装为<packaging>pom</packaging>
。这意味着这是一个 meta-project,不应包含任何源代码。
您需要做的是移动任何现有模块中的测试或为这些测试创建一个新模块。通过查看测试的包结构,我猜你的情况是 automation-ui
。
然后使用以下命令运行所有模块的测试
mvn test -am
其中 -am
将生成所有子模块。
如果要运行 测试单个模块,请使用
mvn test -pl <submodule-name>
所以最终我所做的是创建另一个用于测试的模块,主项目模块将仅包含@Yasin建议的元数据,我还从我的主项目模块中删除了 'src' 包,只留下一个pom.xml 将管理其他模块(反应器)的文件。 现在一切正常。
谢谢!