In this article we are going to see how we can manage Jmeter Test Cases in maven plugin. This is continuation post of this original article.

Defaults : Run All Tests

By default maven jmeter plugins assume your all test cases are present in /src/test/jmeter folder. So when you just specify jmeter executions, it will run all the test, no need specify any test.

<execution>
	<id>jmeter-tests</id>
	<goals>
		<goal>jmeter</goal>
	</goals>
</execution>

Specify Folder for Test Cases

To change default test case folder , we need to use testFilesDirectory

<configuration>
    <testFilesDirectory>${project.basedir}/src/test/testcases</testFilesDirectory>
</configuration>

Example Project

  • In here I have added testcases folder under /src/test/
  • Default /src/test/jmeter folder has BDJOBS1.jmx, BDJOBS2.jmx
  • Our Selected /src/test/testcases folder has only BDJOBS.jmx. We will see only this test case executed and result produced.

custom-folder

Specify JMX to run

If you want to run specific tests, you should add in configuration with testFilesIncluded

<testFilesIncluded>
    <jMeterTestFile>test1.jmx</jMeterTestFile>
</testFilesIncluded>

Now, if you want to add multiple test cases, just add multiple test file

<testFilesIncluded>
    <jMeterTestFile>BDJOBS1.jmx</jMeterTestFile>
    <jMeterTestFile>BDJOBS2.jmx</jMeterTestFile>
</testFilesIncluded>

Multiple JMX Example

  • It has 3 JMX files
  • Only 2 of those are selected
  • We can see only two test case run and report generated.

multiple-jmx

multiple-jmx-results

Specify JMX to run by Regular Expression

If you want to run test cases with specific regular expression patterns, you can use regex.

For example, you want to run different type of login scenarios where each jmx contain each type of log-ins, so you should use like this. In here all login related test cases has prefix login.

<testFilesIncluded>
	<jMeterTestFile>login*.jmx</jMeterTestFile>
</testFilesIncluded>

Multiple JMX Example with regix

  • We have 3 jmx in the folder
  • We select regex login*.jmx which is present as prefix in 2 test cases. So, these 2 will run.

multiple-jmx-regex

multiple-jmx-results-regex

Excluding JMX

If you have many test cases in jmeter folder and you want to exclude test cases, you have to use testFilesExcluded

<testFilesExcluded>
	<excludeJMeterTestFile>test3.jmx</excludeJMeterTestFile>
</testFilesExcluded>

Like include , exclude also supports multiple files

<testFilesExcluded>
	<excludeJMeterTestFile>BDJOBS1.jmx</excludeJMeterTestFile>
    <excludeJMeterTestFile>BDJOBS2.jmx</excludeJMeterTestFile>
</testFilesExcluded>

Exclude JMX Example

  • We have 3 test cases
  • We excluded 2 of those and only one test case will run & report will be generated.

exclude-jmx-results

Excluding JMX with Regex

Like include you can also use regex to exclude. From include example, if we want to exclude all login test cases, we will use like this

<testFilesExcluded>
	<excludeJMeterTestFile>login*.jmx</excludeJMeterTestFile>
</testFilesExcluded>

Multiple Exclude JMX Example with regix

  • we have 3 test cases
  • 2 test cases were exceeded with regex login*.jmx. So, only 1 test case will run.

multiple-jmx-results-regex-exclude

Notes :

  • Multiple tests will run serial , not in parallel.

Thanks :)