在 maven 中运行单个测试 ->未执行任何测试 [英] Running a single test in maven -> No tests were executed

查看:34
本文介绍了在 maven 中运行单个测试 ->未执行任何测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用此命令在 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 以找出它的来源并向依赖项添加排除项.

Run mvn dependency:tree to find out where it's coming in from and add an exclude to the dependency.

这篇关于在 maven 中运行单个测试 ->未执行任何测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆