2016-04-15 100 views
1

我有,当我运行它们在Eclipse中JUnit测试之间的差异,当他们被行家运行万无一失pluging做从终端为什么mvn clean install和eclipse在运行的junit测试中有所不同?

mvn clean install一个项目,当我用鼠标右键单击在Eclipse src/test/java,Junit的告诉我有137个测试运行。做mvn clean install只给了我119.在这一个,似乎在测试名称的情况下可能是一个可能的解释一些测试不以小写字母开头,这使得他们无视它们,但有没有其他可能的解释?

在第二个项目中,我有一个更令人讨厌的问题:整个测试包没有运行mvn clean install。我有src/test/java下的2个包:com.projectcom.project.servicescom.project下的测试课程通过surefire正确运行,而不是com.project.services下的测试课程。

我能看到的唯一特异性com.project.services下类有继承的几个层次:

public class ActualTestsCasesA extends GenericTestSituationA {} 

public class GenericTestSituationA extends ServicesAbstractTests {} 

public abstract ServicesAbstractTests extends ProjectAbstractTests {} 

ActualTestsCasesAGenericTestSituationAServicesAbstractTests都在com.project.services测试包。 ProjectAbstractTests保持在另一个Maven项目中。

这里是我的pom.wml的依赖,以万无一失的插件:

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.18.1</version> 
      <configuration> 
       <forkMode>always</forkMode> 
       <encoding>${project.build.sourceEncoding}</encoding> 
       <sourceEncoding>${project.build.sourceEncoding}</sourceEncoding> 
      </configuration> 

     </plugin> 
+0

'mvn help:effective-pom'在每个环境中运行时会返回不同的结果吗? –

+0

在pom.xml中查看eclipse有效的pom选项卡,surefire-plugin部分在两侧都是相同的。 –

+1

检查单元测试的名称。你是否遵循像'* Test.java *'这样的单元测试的命名约定? – khmarbaise

回答

1

正如你已经发现,运行测试时神火具有特定的命名约定。但是,您可以配置其他naminig约定来匹配您自己的项目的测试文件名。这对于未遵守Maven标准的遗留测试或者您不想重构的大套测试​​类都是有用的。

退房有关详细信息,神火文档:http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

在你的情况,你可以配置一定能成功的,包括像这样具有附加的模式测试类:

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.18.1</version> 
      <configuration> 
       <forkMode>always</forkMode> 
       <encoding>${project.build.sourceEncoding}</encoding> 
       <sourceEncoding>${project.build.sourceEncoding}</sourceEncoding> 
      <includes> 
        <include>**/*Tests*.*</include> 
        <include>**/*TestSituation*.*</include> 
      </includes> 
      </configuration> 

     </plugin> 

Eclipse的,但是,是不是绑定受到这样的限制。相反,它依赖于junit4库的存在来运行测试,并允许jUnit本身来确定一个类是否被认为是可运行测试。请参阅Eclipse Mars docs了解更多信息。

相关问题