iAutomate iAutomate - 6 months ago 33
Java Question

No test case executed when batch file is executed via jenkins even after a successfull build

I an trying to execute test cases in TestNG. I have created a TestNG.xml file. I want to run it via jenkins so i have created a batch file for the same. when i run the testNG.bat from the jenkins. it shows the build status as 'Success' But no test cases got executed. same testng.xml works fine when ran in eclipse.

Following is the TestNG.xml--

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<classes>
<class name="pkg1.Class1"/>
<class name="pkg1.Class3"/>
<class name="pkg2.Class4"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->


following is the Testng.bat---

cd C:\Users\Vinay\workspace_n\$$POM
set ProjectPath=C:\Users\Vinay\workspace_n\$$POM
echo %ProjectPath%
set classpath=%ProjectPath%\bin;%ProjectPath%\lib\*
echo %classpath%
java org.testng.TestNG %ProjectPath%\testng.xml
pause


Following are the result after running the build on jenkins

10:30:18 Started by user anonymous
10:30:18 Building in workspace C:\Users\Vinay\workspace_n\$POM
10:30:18 [$POM] $ cmd /c call C:\Windows\TEMP\hudson7515512989309656489.bat
10:30:18
10:30:18 C:\Users\Vinay\workspace_n\$POM>cd C:\Users\Vinay\workspace_n\$$POM
10:30:18
10:30:18 C:\Users\Vinay\workspace_n\$$POM>set ProjectPath=C:\Users\Vinay\workspace_n\$$POM
10:30:18
10:30:18 C:\Users\Vinay\workspace_n\$$POM>echo C:\Users\Vinay\workspace_n\$$POM
10:30:18 C:\Users\Vinay\workspace_n\$$POM
10:30:18
10:30:18 C:\Users\Vinay\workspace_n\$$POM>set classpath=C:\Users\Vinay\workspace_n\$$POM\bin;C:\Users\Vinay\workspace_n\$$POM\lib\*
10:30:18
10:30:18 C:\Users\Vinay\workspace_n\$$POM>echo C:\Users\Vinay\workspace_n\$$POM\bin;C:\Users\Vinay\workspace_n\$$POM\lib\*
10:30:18 C:\Users\Vinay\workspace_n\$$POM\bin;C:\Users\Vinay\workspace_n\$$POM\lib\*
10:30:18
10:30:18 C:\Users\Vinay\workspace_n\$$POM>java org.testng.TestNG C:\Users\Vinay\workspace_n\$$POM\testng.xml
10:30:19 [TestNG] Running:
10:30:19 C:\Users\Vinay\workspace_n\$$POM\testng.xml
10:30:19
10:30:19
10:30:19 ===============================================
10:30:19 Suite
10:30:19 Total tests run: 0, Failures: 0, Skips: 0
10:30:19 ===============================================
10:30:19
10:30:19
10:30:19 C:\Users\Vinay\workspace_n\$$POM>pause
10:30:19 Press any key to continue . . .
10:30:19
10:30:19 C:\Users\Vinay\workspace_n\$$POM>exit 0
10:30:20 Finished: SUCCESS


Updated the batch file to following.

cd C:\Users\Vinay\workspace_n\$$POM
set ProjectPath=C:\Users\Vinay\workspace_n\$$POM
echo %ProjectPath%
set classpath=%ProjectPath%\bin;%ProjectPath%\lib\*
echo %classpath%
java org.testng.TestNG -log 10 %ProjectPath%\testng.xml
pause


i am getting the following results.

09:55:05 C:\Users\Vinay\workspace_n\$$POM>java org.testng.TestNG -log 10 C:\Users\Vinay\workspace_n\$$POM\testng.xml
09:55:05 [TestRunner] Running the tests in 'Test' with parallel mode:false
09:55:05 [RunInfo] Adding method selector: org.testng.internal.XmlMethodSelector@490d6c15 priority: 10
09:55:05 [TestNGClassFinder] SKIPPING CLASS class pkg1.Class3 no TestNG annotations found
09:55:05 [TestNGClassFinder] SKIPPING CLASS class pkg2.Class4 no TestNG annotations found
09:55:05 [TestNGClassFinder] SKIPPING CLASS class pkg1.Class1 no TestNG annotations found
09:55:05 [TestNG] Running:
09:55:05 C:\Users\Vinay\workspace_n\$$POM\testng.xml
09:55:05
09:55:05 [SuiteRunner] Created 1 TestRunners
09:55:05 [TestRunner] Running test Test on 0 classes, included groups:[] excluded groups:[]
09:55:05 [TestNG] RUNNING: Suite: "Test" containing "0" Tests (config: C:\Users\Vinay\workspace_n\$$POM\testng.xml)
09:55:05 ===== Invoked methods
09:55:05 =====
09:55:05 Creating C:\Users\Vinay\workspace_n\$$POM\test-output\Suite\Test.html
09:55:05 Creating C:\Users\Vinay\workspace_n\$$POM\test-output\Suite\Test.xml
09:55:05
09:55:05 ===============================================
09:55:05 Test
09:55:05 Tests run: 0, Failures: 0, Skips: 0
09:55:05 ===============================================
09:55:05


Following is one of the class.

package pkg1;

import org.testng.annotations.Test;


public class Class1 {

@Test(priority=1)
void pkg111() {
System.out.println("pkg1 class1 p1");
}

@Test(priority=4)
void pkg121() {
System.out.println("pkg1 class1 p4");
}

@Test(priority=3)
void pkg131() {
System.out.println("pkg1 class1 p3");
}
}

Answer Source

Followed the steps provided by @juherr and I have updated the TestNG version from 6.8 to 6.11. Now i am able to executed test cases via jenkins.