Xceptance / neodymium-library

A test automation library based on common other best practice open source libraries. It adds missing functionalities but does not reinvent the wheel. Just glues stuff together nicely and adds some sprinkles.
MIT License
80 stars 11 forks source link

#179 Filter test methods for execution by regex from configuration file #186

Closed oomelianchuk closed 3 years ago

oomelianchuk commented 3 years ago

The changes in NeodymiumRunner.computeTestMethods are meant to filter the test methods by applying the regex from the neodymium.testExecutionRegex on the already generated method description.

To avoid redundant error message for the tests, which should not be executed, the validateInstanceMethods of BlockJUnit4ClassRunner was overridden to ignore the test classes with no runnable methods if the neodymium.testExecutionRegex is configured.

The feature allows to filter test cases for execution via neodymium property like the following: neodymium.testExecutionRegex=".*LoginTest#testLoginWithPasswordFailure\s::\swrong\spassword.*" ( This is not obligatory to mention all the parts of the test description. If you don't want to specify the part, simply replace it with .*)

More useful, however, might be passing this property for specific maven profile like here:

<profiles>
   <profile>
      <id>missing</id>
      <activation>
         <activeByDefault>true</activeByDefault>
      </activation>
      <build>
         <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-surefire-plugin</artifactId>
               <configuration>
                  <systemProperties>
                     <property>
                        <name>neodymium.testExecutionRegex</name>
                        <value>.*LoginTest#testLoginWithoutRequiredFields\s::\smissing\spassword.*</value>
                     </property>
                  </systemProperties>
               </configuration>
            </plugin>
         </plugins>
      </build>
   </profile>
   <profile>
      <id>wrong</id>
      <build>
         <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-surefire-plugin</artifactId>
               <configuration>
                  <systemProperties>
                     <property>
                        <name>neodymium.testExecutionRegex</name>
                        <value>.*LoginTest#testLoginWithPasswordFailure\s::\swrong\spassword.*</value>
                     </property>
                  </systemProperties>
               </configuration>
            </plugin>
         </plugins>
      </build>
   </profile>
</profiles>