![]() ![]() NB1 If double quotation mark(“) is used instead of apostrophe(‘) the command will not be interpreted properly and will produce unexpected results. The above command will exclude all the tests that contain excludedString. Using Surefire Plugin 2.19 you can simply exclude the tests you don’t want using regular expressions: That is, then at runtime you decide, without any need to change the pom.xml file or activating any profile. Mvn clean test > would not skip anything (or fall back on default behavior) Mvn clean test -Dtest.regex=".+" > will skip all module tests Mvn clean test -Dtest.regex="(module1)|(module2)|(module3)" > will skip the three module tests Mvn clean test -Dtest.regex="(module1)|(module2)" > will skip tests on module1 and module2 Then from command line we could have mvn clean test -Dtest.regex="(module1)" > will skip tests only for module1 Here we are actually replacing the regex value with a property, test.regex, with default value to none (or whatever would not match any module name or, also, the default skipping matchings required). You could also go further and have dynamic behavior based on your input: Obviously, if this is not the default behavior of the build (recommended case), you could always wrap the snippet above in a maven profile. The advantage of this approach is to have it dynamic and centralized (in the parent pom.xml) hence better for maintenance: you could add or remove modules at any time simply by changing the simple regex above. ![]() In this case, tests will be skipped for module1 and module3 while running properly for module2, that is, as expressed by the regex. Thanks to the build-helper-maven-plugin you would actually dynamically check whether you are in a certain module or not during the build, via the project.artifactId property (pointing at each artifactId module during the build), the regex would then seek matching for certain values (the module names for which you want to skip tests) and populated the property accordingly (setting it to true). If you have a large multi-module project and you would like to skip tests only in certain modules without the need to change each of the module pom.xml file with custom configuration and profiling, you could add the following to the parent pom.xml file: If you run mvn clean package -DnoTest=true, it will not run the tests for this module. With the latter solution, if you run mvn clean package, it will run all tests. What about skipping tests only in this module ?Įventually, you can create a profile that will disable the tests (still the pom.xml of the module) : My.package.?ExcludedTest, another.package.6 thoughts on “ Skipping tests in some modules in Maven” %regex, !%regex, pkg/**/*Fast*.java, Basic?, !Unstable*Īs of Surefire Plugin 2.19.1, the syntax with fully qualified class names or packages can be used, e.g.: Īn include/exclude pattern can be an ant-style path expression, but regular expressions are also supported through this syntax: Īs of Surefire Plugin 2.19, a complex syntax is supported in one parameter (JUnit 4, JUnit 4.7+, TestNG): Exclusions can be done by configuring the excludes property of the plugin. Excluding them is one of the best workarounds to continue the build. There are certain times when some tests are causing the build to fail. If the test classes do not follow any of these naming conventions, then configure Surefire Plugin and specify the tests you want to include. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |