Saturday, December 30, 2017

Maven Tutorial 05: Maven Surefire plugin and its usage in test automation?

Maven Surefire Plugin is used during test phase of build life cycle to execute the unit tests of an application. It has only one goal and it is 'test', runs the tests of the application. In test automation surefire plugin can be used for running functional tests from pom.xml.

Configure surefire plugin maven project:

In the Maven project open the pom.xml and add below plugin inside <build></build> tags.

Inclusion and Exclusion of Tests:

By default, the surefire plugin will include all test classes with the following wildcard patterns:

  • "**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
  • "**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
  • "**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
  • "**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".
If the test classes do not follow any of these naming conventions, we need to configure Surefire plugin and specify the tests we want to include as shown in the pom.xml below.

To specify the class we want to include to run the tests, we have to include it inside <includes></includes>.

Exclusion of Tests:

Similarly, if we want to exclude particular tests from the execution we can specify using surefire plugin as shown below.

To specify the class we want to exclude, we have to include it inside <excludes></excludes>.

These are some of the usages of  Surefire plugin in Maven. Please comment your queries and suggestions on this topic. Thanks for reading!!

#seleniumbabu #HappyLearning #HappyTesting #qababu

No comments:

Post a Comment

Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...