java - 在 maven 中运行单个测试 -> 未执行任何测试

标签 java testing selenium maven functional-testing

当我使用此命令在 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/

相关文章:

java - Mockito Java 测试总是通过 - 我做错了什么?

测试重新安装 - 我需要一个保存文件的方法/程序

Python Selenium Firefox 脚本在重新启动驱动程序实例后崩溃

java - 如何在 Java 或 clojure 中使用 ImageJ 进行批量图像处理?

java - iText 5.0.0 RTF 和 HTML 去哪儿了?

javascript - 如何验证元素是否存在于 CucumberJS 和 Protractor 中?

python selenium 示例不起作用,说没有名为 Keys 的模块

java - XML Dom 处理

java - JSF - selectItems 不会在列表内呈现列表

python - 如何从动态网站 python selenium 中检索表