2017-07-09 91 views
0
mvn test -Dgroups=group3,group2 

将执行groups3和分组2 - 按Can I run a specific testng test group via maven?我可以通过maven排除特定的testng测试组吗?

我想运行所有测试是在一组。这可能通过maven吗?例如。我想运行所有不在group3中的测试。 !

“假行家命令” MVN测试-Dgroups =组3

+1

可能的重复:https://stackoverflow.com/questions/9123075/maven-how-can-i-skip-test-in-some-projects-via-command-line-options –

回答

1

据官方TestNG的文档,请参阅 “命令行参数” 表在这里http://testng.org/doc/documentation-main.html#running-testng,它应该是可能的:

$ mvn test -Dexcludegroups=group3 

然而,为了获得更大的灵活性,我建议使用test suite configuration文件(又名testng.xml),其位置可以通过<suiteXmlFile>配置surefire-plugin的属性,请参阅:http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

这将允许完全控制组包含/排除,请参阅:http://testng.org/doc/documentation-main.html#exclusions

+0

当您使用Maven运行它时在Surefire中,你需要的参数是“-DexcludedGroups = groupfoo”。请参阅http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html – AgentME

1

是的,你可以在TestNG中使用beanshell来做到这一点。

创建一套XML文件,并定义为以下的BeanShell:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="Suite" parallel="false"> 
    <test name="Test"> 
     <method-selectors> 
      <method-selector> 
       <script language="beanshell"> 
       <![CDATA[whatGroup = System.getProperty("groupToRun"); 
       !Arrays.asList(testngMethod.getGroups()).contains(whatGroup); 
       ]]> 
       </script> 
      </method-selector> 
     </method-selectors> 
     <classes> 
      <class name="organized.chaos.GroupsPlayGround" /> 
     </classes> 
    </test> <!-- Test --> 
</suite> <!-- Suite --> 

这将导致基本TestNG的寻找这是通过JVM参数groupToRun通过了不属于该组的所有测试

我在我的博客here中解释过这个问题。

您还可以在官方TestNG文档here中找到更多相关信息。

相关问题