在 Maven 中运行单个测试 -> 没有执行任何测试

新手上路,请多包涵

当我使用此命令在 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 许可协议

阅读 812
2 个回答

您可能在某个地方的类路径中选择了 JUnit3,这实际上禁用了 JUnit4。

运行 mvn dependency:tree 找出它来自哪里,如果来自依赖项则添加排除。

原文由 krosenvold 发布,翻译遵循 CC BY-SA 4.0 许可协议

也许您看到了 这个 据说会影响 surefire 2.12 但不会影响 2.11 的错误?

原文由 joel truher 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题