【发布时间】:2020-04-01 09:18:57
【问题描述】:
我知道你一开始会怎么想:“你应该在命名你的测试类时加上‘Test’等等。” 但问题是:情况已经如此。我确实滚动了所有可能的 SO 帖子,但没有找到任何东西,所以不,很遗憾,这不是重复的。
我什至有一个名为 TestPleaseWillYouRunMyTest 的测试类和一个名为 testPleaseTest() 的测试方法。
当我运行“mvn test”时,“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>
【问题讨论】:
-
您想使用哪个测试框架:JUnit Jupiter 还是 TestNG?顺便说一句:删除
<testSourceDirectory> src/test/java </testSourceDirectory>让 Maven 处理。 -
将源和目标设置为 10 并不是最好的主意。使用 LTS 版本,如 Java 8 或 Java 11。
-
能否分享一下你的测试类样本
-
为什么要添加 testng、junit 4 和 5?首先决定你要使用哪个测试框架
-
@Nomanaliabbasi 你帮我解决了我的问题:我不得不从我的 POM 中删除 testng 依赖项。请把它写成这篇文章的答案,这样我就可以为你提供你应得的所有代表:)
标签: java maven selenium intellij-idea