2011-01-10 234 views
17

当我运行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(); 

} }

UPDATE:

它加入这个依赖于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

你想运行什么样的考验?你没有任何机会放置@Ignore? – Navi 2011-01-10 10:59:09

+0

可能不太有用..但请记住,这两个都是测试版产品,并大大受到破坏。 – mezmo 2011-01-10 20:35:35

回答

5

您可能正在某处找到类路径上的JUnit3,这有效地禁用了JUnit4。

运行mvn依赖关系:树找出它来自哪里并将排除添加到依赖项。

0

尝试在调试模式下运行maven。它可能会给你更多的信息。

mvn -X -Dtest=InitiateTest test 
-2

我真的不知道@Test注释如何处理您的测试,但是您可以尝试在“测试”前添加测试方法的前缀吗?

public void testInit() throws Exception { 
     driver.get("http://localhost:8080/login.jsp"); 
     ... 
} 
+0

@JUnit 4中引入了测试注释,在jUnit 3中,每种方法都必须以“test” – Kennet 2011-01-10 11:13:01

+0

开始,但不幸的是这种方法没有帮助。 @Test注释就够了。 – 2011-01-10 11:48:03

-1

也许是没用,因为我的最后一次尝试,但我刚刚看了一个JUnit 4测试类应该导入org.junit.Test。* 和org.junit.Assert。*被认为是如此。 由于您没有Assert导入,因此可能需要快速尝试以确保...

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> 
+0

这对我来说也是一样的......一分钟前我发现了这个:/ THX man – yoosiba 2011-05-11 21:39:04

0

有类似的问题添加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> 
11

也许你看到this bug,排除说法,据说这是影响万无一失2.12而不是2.11?

3

我已将“maven-surefire-plugin”更改为2.14.1版本(从2开始)。12),它帮助

-1

在我的情况下,我正在使用mvn test -Dtest = MyTest运行单个测试。我的错误是,唯一的测试有@test注释注释掉,所以junit没有在文件中找到测试。卫生署!

0

从2.6改为2.18.1,它仍然可以帮助

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> 
-1
mvn test -Dtest='xxxx.*Test' -Dmaven.test.failure.ignore=true -DfailIfNoTests=false 

我也满足同样的问题,没有测试已经执行! 我的建议是添加另一个参数-Dmaven.test.failure.ignore=true -DfailIfNoTests=false可以解决它。

0

我有类似的问题。所以我不得不建设项目使用

mvn clean install -DskipTests=True 

然后运行从目录中测试命令项目的根级其中测试包的POM是居住

mvn test -Dtest=TestClass 

还要确保价值的跳过选项是正确的。例如在我的pom文件中,skip的默认值为true。

<properties> 
    <skipTests>true</skipTests> 
</properties> 


<build> 
    <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <configuration> 
       <skip>${skipTests}</skip> 
      </configuration> 
    </plugin> 
</build> 

所以,当我运行Maven的测试,我将它设置为false

mvn test -Dtest=TestUserUpdate* -DskipTests=false