在maven中运行单个测试 - >没有执行任何测试! [英] Running a single test in maven -> No tests were executed!
问题描述
当我使用此命令在Maven中运行单个测试时:
When I run a single test in Maven with this command:
mvn test -Dtest=InitiateTest
我得到以下结果:
No tests were executed!
它在几分钟前工作,但现在由于某种原因它停止了工作。我在运行测试之前尝试运行 mvn clean
几次,但没有帮助。
It worked a couple of minutes ago, but now it stopped working for some reason. I tried running mvn clean
a couple of times before running the test, it doesn't help.
测试看起来像这样:
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所致:
It's caused by adding this dependency to POM:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0b1</version>
<scope>test</scope>
</dependency>
当我删除它时,一切正常。即使我添加这两个依赖项而不是前一个依赖项,一切正常:
When I remove it, everything works fine. Everything works fine even when I add these two dependencies instead of the previous one:
<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>
这很奇怪。
推荐答案
您可能正在某个类路径上拾取JUnit3,这会有效地禁用JUnit4。
You are probably picking up JUnit3 on your classpath somewhere, which effectively disables JUnit4.
运行mvn dependency:tree以查找它的来源in from并向依赖项添加一个排除。
Run mvn dependency:tree to find out where it's coming in from and add an exclude to the dependency.
这篇关于在maven中运行单个测试 - >没有执行任何测试!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!