在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>
这很奇怪。
When I run a single test in Maven with this command:
mvn test -Dtest=InitiateTest
I'm getting the following result:
No tests were executed!
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.
The test looks like this:
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();
}
}
UPDATE:
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>
This is weird.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
我已将“maven-surefire-plugin”更改为 2.14.1 版本(从 2.12 开始),它有帮助
I have changed "maven-surefire-plugin" to 2.14.1 version (from 2.12) and it helped
添加 jtestr 依赖项时遇到类似问题。事实证明,它的依赖项之一是 junit-3.8.1。我使用下面的排除语句解决了这个问题
Had a similar problem adding jtestr dependency. It turns out one of its dependencies was picking up junit-3.8.1. I solved it using the exclusion statement below
就我而言,我使用 mvn test -Dtest=MyTest 运行单个测试。我的错误是唯一的测试已注释掉其 @test 注释,因此 junit 在文件中找不到测试。哎哟!
In my case, I was running a single test using mvn test -Dtest=MyTest. My mistake was that the only test had its @test annotation commented out so no test was being found in the file by junit. Doh!
在 pom.xml 的构建会话中,包含以下内容:
In the build session of the pom.xml, include this:
我有类似的问题。因此,我必须使用从项目的根级别构建项目
然后从测试包的pom所在的目录运行测试命令
还要确保skip选项的值为真的。例如在我的pom文件中,skip的默认值为true。
所以当我运行maven测试时,我将其设置为 false
I had a similar issue. So I had to build the project from project's root level using
And then run the test command from the directory where test package's pom was residing
Also make sure that value of skip option is true. For example in my pom file, the default value of skip is true.
So when I run the maven test, I set it to false
从 2.6 更改为 2.18.1,现在一切正常
changed from 2.6 to 2.18.1 and things work now
更新 org.apache.maven.plugins:maven-surefire-plugin 到 2.22.0,已解决。
update the org.apache.maven.plugins:maven-surefire-plugin to 2.22.0, it was resolved.
尝试在调试模式下运行 Maven。它可能会为您提供更多信息。
Try running maven in debug mode. It might give you more information.
我在复制和重构不同类的测试时遇到了这个问题。
该问题是用
@Test
注释private
方法,导致它被忽略,更改为public
解决了该问题。 :捂脸:I had this issue when duplicating and refactoring a test from a different class.
The issue was annotating a
private
method with@Test
, causing it to be ignored, changing topublic
fixed the issue. :facepalm:也许和我上次的尝试一样没用,但我刚刚读到 JUnit 4 测试类应该导入 org.junit.Test.* and org.junit.Assert.* 被认为是这样。
由于您没有 Assert 导入,因此可能值得快速尝试以确保......
Maybe as useless as my last attempt, but I just read a JUnit 4 test class should import org.junit.Test.* and org.junit.Assert.* to be considered so.
As you don't have the Assert import, it might be worth trying this quickly just to be sure...
我遇到了同样的问题,没有执行任何测试!
我的建议是添加另一个参数
-Dmaven.test.failure.ignore=true -DfailIfNoTests=false
可以解决它。I have meet the same question that No tests were executed!
My suggestion is add another paramters that
-Dmaven.test.failure.ignore=true -DfailIfNoTests=false
can solve it.我真的不知道 @Test 注释如何处理您的测试,但是您可以尝试在测试方法前加上“test”前缀吗?
I don't really how the @Test annotation processes your test, but can you try prefixing your test method with "test"?
您可能在类路径中的某处选择了 JUnit3,这实际上禁用了 JUnit4。
运行
mvn dependency:tree
以找出它的来源并添加从依赖项中排除的内容。You are probably picking up JUnit3 on your classpath somewhere, which effectively disables JUnit4.
Run
mvn dependency:tree
to find out where it's coming in from and add exclude if from the dependency.也许您正在看到此错误,据说该错误会影响surefire 2.12,但不会影响2.11?
Perhaps you are seeing this bug, which is said to affect surefire 2.12 but not 2.11?
我也有同样的问题。这是由于junit3自带的testng依赖引起的。只需为其添加排除声明,测试就应该可以工作。
I had the same problem. It was caused by testng dependency that came with junit3. Just add a exclusion statement for it and tests should work.
尝试使用
@org.junit.Test
时出现此错误要使用的正确注释是
@org.junit.jupiter.api.Test
I got this error when trying to use
@org.junit.Test
with
The correct annotation to be used is
@org.junit.jupiter.api.Test