当我使用此命令在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>
这很奇怪。
答案 0 :(得分:11)
也许你看到this bug,据说影响了surefire 2.12而不是2.11?
答案 1 :(得分:6)
您可能正在某个类路径上拾取JUnit3,这会有效地禁用JUnit4。
运行mvn dependency:tree以查找它的来源并向依赖项添加一个排除。
答案 2 :(得分:6)
我遇到了同样的问题。它是由junit3附带的testng依赖引起的。只需为它添加一个排除声明,测试就可以了。
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0b1</version>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
答案 3 :(得分:2)
我已将“maven-surefire-plugin”更改为2.14.1版本(从2.12开始)并帮助
答案 4 :(得分:1)
有一个类似的问题,添加jtestr依赖。事实证明其中一个依赖关系正在接受junit-3.8.1。我使用下面的排除声明解决了它
<dependency>
<groupId>org.jtestr</groupId>
<artifactId>jtestr</artifactId>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
<version>0.6</version>
<scope>test</scope>
</dependency>
答案 5 :(得分:1)
我有类似的问题。所以我必须使用
从项目的根级别构建项目./configure
然后从测试包的pom 所在的目录运行测试命令
movic/Downloads/php-5.1.0/ext/dom/documenttype.c -o ext/dom/documenttype.lo
/home/tomovic/Downloads/php-5.1.0/meta_ccld -Iext/dom/ -I/home/tomovic/Downloads/php-5.1.0/ext/dom/ -DPHP_ATOM_INC -I/home/tomovic/Downloads/php-5.1.0/include -I/home/tomovic/Downloads/php-5.1.0/main -I/home/tomovic/Downloads/php-5.1.0 -I/usr/include/libxml2 -I/home/tomovic/Downloads/php-5.1.0/ext/date/lib -I/home/tomovic/Downloads/php-5.1.0/TSRM -I/home/tomovic/Downloads/php-5.1.0/Zend -D_REENTRANT -g -O2 -pthread -Wall -DZTS -c /home/tomovic/Downloads/php-5.1.0/ext/dom/documenttype.c -fPIC -DPIC -o ext/dom/.libs/documenttype.o
/home/tomovic/Downloads/php-5.1.0/ext/dom/documenttype.c: In function 'dom_documenttype_internal_subset_read':
/home/tomovic/Downloads/php-5.1.0/ext/dom/documenttype.c:219:42: error: dereferencing pointer to incomplete type 'xmlBuf {aka struct _xmlBuf}'
strintsubset = xmlStrndup(buff->buffer->content, buff->buffer->use);
^
Makefile:408: die Regel für Ziel „ext/dom/documenttype.lo“ scheiterte
make: *** [ext/dom/documenttype.lo] Fehler 1
root@DELL:~/Downloads/php-5.1.0#
还要确保skip选项的值为true。例如,在我的pom文件中,skip的默认值为true。
mvn clean install -DskipTests=True
因此,当我运行maven测试时,我将其设置为false
mvn test -Dtest=TestClass
答案 6 :(得分:1)
尝试使用@org.junit.Test
使用
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
要使用的正确注释是@org.junit.jupiter.api.Test
答案 7 :(得分:0)
尝试在调试模式下运行maven。它可能会为您提供更多信息。
mvn -X -Dtest=InitiateTest test
答案 8 :(得分:0)
在我的情况下,我使用mvn test -Dtest = MyTest运行单个测试。我的错误是唯一的测试有@test注释被注释掉,所以junit没有在文件中找到测试。卫生署!
答案 9 :(得分:0)
从2.6更改为2.18.1,仍有帮助
答案 10 :(得分:0)
在pom.xml的构建会话中,包括:
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
</plugin>
</plugins>
</build>
答案 11 :(得分:0)
将org.apache.maven.plugins:maven-surefire-plugin更新为2.22.0,已解决。
答案 12 :(得分:0)
从另一个类复制和重构测试时遇到了这个问题。
问题是用private
注释了@Test
方法,导致该方法被忽略,更改为public
解决了该问题。 :facepalm:
@Test
public void testImportOrderItems() {
答案 13 :(得分:-1)
也许和我上一次尝试一样没用,但我刚读了一个JUnit 4测试类应该导入org.junit.Test。* 和org.junit.Assert。* 这样做。 由于您没有Assert导入,因此可能需要快速尝试以确保...
答案 14 :(得分:-2)
我真的不知道@Test注释如何处理您的测试,但是您可以尝试使用“test”为测试方法添加前缀吗?
public void testInit() throws Exception {
driver.get("http://localhost:8080/login.jsp");
...
}
答案 15 :(得分:-2)
mvn test -Dtest='xxxx.*Test' -Dmaven.test.failure.ignore=true -DfailIfNoTests=false
我遇到的问题是没有执行任何测试!
我的建议是添加另一个-Dmaven.test.failure.ignore=true -DfailIfNoTests=false
可以解决它的参数。