java - TestNG mvn run tests without group -


i using testng , maven surefire plugin run tests. have:

@test(groups={"groupa"}) testa{}  @test testb 

i have possibility run:

mvn test  

should invoke test without group

mvn test -dgroups=groupa 

should invoke groupa tests ( works default added here have working previous option )

i tried configure surefire like:

<plugin>  <groupid>org.apache.maven.plugins</groupid>  <artifactid>maven-surefire-plugin</artifactid>  <version>2.16</version>  <configuration>    <excludedgroups>groupa</excludedgroups>  </configuration> </plugin> 

mvn test works expected, after
mvn test -dgroups=groupa no tests executed

edit

i found solution here: https://labs.consol.de/blog/maven/citrus-and-testng-groups/

<!-- testng groups --> <testgroups></testgroups> <testgroupsexcluded>groupa</testgroupsexcluded> <!-- /testng groups--> ... <plugin>  <groupid>org.apache.maven.plugins</groupid>  <artifactid>maven-surefire-plugin</artifactid>  <version>2.16</version>  <configuration>        <groups>${testgroups}</groups>    <excludedgroups>${testgroupsexcluded}</excludedgroups>  </configuration> ...   <profile> <id>a-testes</id> <properties> <testgroups>a</testgroups> <testgroupsexcluded></testgroupsexcluded> </properties>  </profile> 

but there 1 problem solution. works fine when want run 1 groups of tests, example mvn test -p a-tests, when add group, let's b-tests, after mvn test -p a-tests, b-tests 1 group executed because last defined profile overide properties... ideas how combine testgroupsexcluded, testgroups properties multiple profiles?

edit 2

i ended solution

 <properties>    <testgroups>unit</testgroups>  </properties>  ... <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-surefire-plugin</artifactid> <version>2.16</version> <configuration>   <groups>${testgroups}</groups> </configuration> </plugin> 

but had assign tests explicitly groups (all unassigned tests 'unit'), can call:

mvn test invoke tests marked unit

mvn test -dtestgroups=groupa, groupb invoke group tests...

dude, have checked http://testng.org/doc/documentation-main.html#beanshell ?

in surefire plugin attach testng suit config:

<configuration>     <suitexmlfiles>         <suitexmlfile>testng.xml</suitexmlfile>     </suitexmlfiles> ... 

in testng.xml

<suite name="emap test suite"> <test name="emap tests">     <method-selectors>         <method-selector>             <script language="beanshell"><![cdata[                     addclasspath("target/test-classes" );                   return com.yourpackage.shouldexecutetest(groups, system.getproperty("groups"));                      ]]> 

in static java method shouldexecutetest can implement rule want!

accoriding doc, can use vars:

java.lang.reflect.method method:  current test method. org.testng.itestngmethod testngmethod:  description of current test method java.util.map<string, string> groups:  map of groups current test method belongs to. 

system.getproperty("groups") -dgroups=xxx passed mvn invocation.

works charm!


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -