当我使用此命令在 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>
这很奇怪。
最佳答案
您可能在某个地方的类路径中选择了 JUnit3,这实际上禁用了 JUnit4。
运行 mvn dependency:tree
找出它的来源并添加 exclude if from the dependency.
关于java - 在 maven 中运行单个测试 -> 未执行任何测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4646014/