我首先知道您会怎么想:“您应该在测试类中命名为'Test'等。”但是问题是:已经是事实了。我确实滚动了所有可能的SO帖子,但是没有找到任何东西,所以不幸的是,这不是重复的。
我什至有一个名为TestPleaseWillYouRunMyTest的测试类和一个名为testPleaseTest()的测试方法。
当我运行“ MVN测试”时,“ target / test-classes”文件夹已被填充,因此我真的不明白为什么我的测试未运行...
以防万一有助于理解问题,这是我的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>org.example</groupId>
<artifactId>SeleniumTests</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
<testSourceDirectory> src/test/java </testSourceDirectory>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
</dependencies>
</project>
我认为问题是您没有surefire插件。我无法在您的Maven Pom文件中找到surefire插件。在构建生命周期的测试阶段使用Surefire插件执行应用程序的单元测试。执行后,它将生成两种不同文件格式的报告,即纯文本文件(.txt)XML文件(.xml)。
有关surefire插件的更多信息,您可以在下面的链接中找到:https://maven.apache.org/surefire/maven-surefire-plugin/
您可以在pom文件中添加以下配置,我认为它会起作用。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>