当我使用此命令在 Maven 中运行单个测试时:
mvn test -Dtest=InitiateTest
我得到以下结果:
No tests were executed!
它在几分钟前工作,但现在由于某种原因停止工作。在运行测试之前,我尝试运行 mvn clean
几次,但没有帮助。
测试看起来像这样:
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class InitiateTest {
public static FirefoxDriver driver;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
@Test
public void initiateTest() throws Exception {
driver.get("http://localhost:8080/login.jsp");
...
}
@After
public void tearDown() throws Exception {
driver.close();
}
}
更新:
这是由于将此依赖项添加到 POM 引起的:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0b1</version>
<scope>test</scope>
</dependency>
当我删除它时,一切正常。即使我添加这两个依赖项而不是前一个依赖项,一切也能正常工作:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.0b1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.0b1</version>
<scope>test</scope>
</dependency>
这很奇怪。
原文由 John Manak 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可能在某个地方的类路径中选择了 JUnit3,这实际上禁用了 JUnit4。
运行
mvn dependency:tree
找出它来自哪里,如果来自依赖项则添加排除。