How to run multiple "mvn test"-commands from batch file?

3.7k views Asked by At

I need to execute maven tests from another program, in this case HP QC/ALM. I want to execute specific tests, and so I have written a .bat-file that looks like this:

cd C:\myPath\
call mvn -Dtest=myPackage.MyTestClass test
call mvn -Dtest=myPackage.MyOtherTest test

First of all I am calling the path where the pom.xml file is located. This is needed even if the .bat-file is in the same directory. second I am calling a specific extension of a TestCase-class, with multiple test methods. I am using JUnit 3. third I am calling another specific TestCase-class.

The first TestCase is executed as expected. My problem is that the execution stops after the first TestCase. The call keyword is supposed to force the execution to continue, but it has no effect here. Wether the tests are succesful or not makes no difference.

I can't seem to find any other suggestions than the call keyword to solve this problem. Am I using it wrong? Does anyone have any idea why it does not work? Are there other solutions or suggestions I could try?

UPDATED WITH ADDITIONAL INFO:

Command line execution stops after the following output:

Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 82.964 sec

Results :

Tests run: 11, Failures: 0, Errors: 0, Skipped: 0

This is the 11 tests included in myPackage.MyTestClass

1

There are 1 answers

0
El David On

the way i use for run specific suite of test cases is:

  1. In the pom.xml, indicate the suites
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">  
....
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <parallel>methods</parallel>
                    <threadCount>10</threadCount>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/java/login/suite001</suiteXmlFile>
                        <suiteXmlFile>src/test/java/other/suite002</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  1. in the suite specifi the test cases do you want included. You can include an entire packege if yoou want.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="suite100LoginCliente" verbose="1" >
    <test name="testName001"   >
        <packages>
            <package name="login" />
        </packages>
    </test>
</suite>
  1. run a batch file to run the test
@echo off
cls
echo Welcome to .
cd C:\blabla\mavenProyect
call mvn test
echo Press anything to exit :D
Pause>Nul

That's all i know until now. If you found a better for way do this, please let know ;)