I installed NetBeans 8.0.1 on my computer and used it to create a test suite :
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="testing">
<test name="suite">
<packages>
<package name="myPackage.tests"/>
</packages>
</test>
</suite>
In myPackage.tests there is a test class, a very simple one :
[package, imports]
public class Tests001 {
public Tests001 () {
}
#Test
public void Fail() {
assertFalse(true);
}
In NetBeans, I launched the test by right-clicking the.xml file and selecting 'test file'. Everything works perfectly - or rather, it correctly fails - intended result for now.
But I need to launch it from console, so I run :
> java org.testng.TestNG testing.xml
And get :
===============================================
testing
Total tests run: 0, Failures: 0, Skips: 0
===============================================
No test is run. I can't find out why : test class and methods are public ; java is configured correctly (JDK 1.8.0_25) and I set CLASSPATH to
C:\Program Files\NetBeans 8.0.1\platform\modules\ext\testng-6.8.1-dist.jar
I must have forgotten something...
Or is there a way, from console, to ask NetBeans to proceed to test ?
In my experience, the suite.xml file needs this structure:
<suite name="mySuite" allow-return-values="true" parallel="tests"
verbose="1" thread-count="2">
<test name="TestStuff">
<groups>
<run>
<include name="Smoke.mytests"/>
</run>
</groups>
<packages>
<package name="com.myco.mytests"/>
</packages>
</test>
</suite>
Related
I would like all my classes running sequentially. Below is my testng xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="instances" thread-count="1">
<test name="Test">
<classes>
<class name="atk.tests.Printer"/>
<class name="atk.tests.Rejecteur"/>
<class name="atk.tests.Specfeatures"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
I've tried in suite name tag to do :
<suite name="Suite" parallel="instances" thread-count="1"> then
<suite name="Suite" parallel="false" >
And then in classes:
<classes parallel="methods">
No solution is working to make my tests running sequentially. For the moment, they are running in parallel and i would like to avoid that.
Is anyone able to provide a solution for that ? Thanks
By default, TestNG will run your tests in the order they are found in the XML file. If you want the classes and methods listed in this file to be run in an unpredictable order, set the preserve-order attribute to false
For this ordering, you can use the XML attribute group-by-instances. This attribute is valid either on <suite> or <test>
<suite name="Suite" group-by-instances="true">
or
<test name="Test" group-by-instances="true">
try once with preserver order true and parallel none
<suite name="Suite" parallel="none" preserve-order="true">
I Have TestNg Class look like the following code:
And I have On Jenkins two jobs: job1 and job2 job1 to execute TestsFluxPro and job2 to execute TestsVente tests
my question is how to configure Jenkins to tell in each job run the chosen class test for example in job 1 I want to execute com. AZ. testsFlux. TestsVente!!!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"
/>
<listener class-name="com.az.utilities.CustomListeners" />
</listeners>
<test name="Managetestss" group-by-instances="true">
<parameter name="browser" value="firefox"></parameter>
<classes>
<class name="com.az.testsFlux.TestsFluxPro" />
<class name="com.az.testsFlux.TestsVente" />
</classes>
</test>
</suite>
Reconsider using testng.xml, you will not be able to parameterize it from Jenkins.
There is a possibility to run your TestNG test in command-line mode where you have -testclass parameter:
-testclass A comma-separated list of classes that can be found in your classpath. A list of class files separated by commas (e.g. org.foo.Test1,org.foo.test2).
So you should be able to kick off your tests execution like:
For com.az.testsFlux.TestsFluxPro :
java -cp "/path/to/test.jar;/path/to/test/dependencies/*" org.testng.TestNG -testclass com.az.testsFlux.TestsFluxPro
For com.az.testsFlux.TestsVente
java -cp "/path/to/test.jar;/path/to/test/dependencies/*" org.testng.TestNG -testclass com.az.testsFlux.TestsVente
To run both:
java -cp "/path/to/test.jar;/path/to/test/dependencies/*" org.testng.TestNG -testclass com.az.testsFlux.TestsVente,com.az.testsFlux.TestsFluxPro
etc.
Actually I'm testing multiple website for my company. All the website have the same structure and i'm testing various things on each.
For my test i have a Selenium Java Maven project using TestNG. For each web site, i've created a sub folder and generate a specific testing.xml file to specify each test i'm doing for the website.
Here the structure : http://imgur.com/g0VHfMw
My testing.xml files are like this :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test suite website 1" parallel="tests" thread-count="2">
<test name="Test1">
<classes>
<class name="package.for.mytest1"></class>
</classes>
</test>
<test name="Test2">
<classes>
<class name="package.for.mytest2"></class>
</classes>
</test>
<test name="Test3">
<classes>
<class name="package.for.mytest3"></class>
</classes>
</test>
</suite>
How can I merge this 4 test suite in one testNG report ? And if it's possible, is there a way to only show the unstable or failed test on it ?
Any ideas ? Thanks for your help
Try Allure it could easily generate combined report for several suites and show only failed/broken tests by default.
Either you can Use Suite-XML tag in TestNG.xml file to report all your test in single report or implement a reporter of your own to collect all the results and then at the end flush everything into report of your own format with whatever information you need.
You can create a separate testng.xml file in which you can give the path of other testsuites files.
eg:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name= "Allsuites" verbose="1" preserve-order="true" >
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"/>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
</listeners>
<suite-files preserve-order="true">
<suite-file path="testng1.xml" />
<suite-file path="testng2.xml" />
<suite-file path="testng3.xml" />
</suite-files>
</suite>
I have created a test using the TestNG framework in Java in Eclipse and want to execute my tests through an XML file by running it through the testNG Suit.
the file system of my folder is illustrated in the following Link screenshot:
1
my java code:
package a;
import org.testng.annotations.Test;
public class Amir {
#Test
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Test Test");
}
}
my xml code:
<?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="a.Amir"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
When i execute above xml using TestNg Suit, on eclipse console i received log as:
[TestNG] Running:
C:\Users\Amir\workspace\SmartAir.co.il\testng.xml
===============================================
Suite
Total tests run: 1, Failures: 0, Skips: 1
===============================================
Could anyone help me on this please?
I found the answer: I have to delete the (String[] args) because TestNG tests do not take any arguments.
I have a JAR(xyz.jar) with test class test.sample.ClassX. I am trying to use this class in testng.xml shown below,
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SuiteX" verbose="1" >
<test name="TestX" >
<classes>
<class name="test.sample.ClassX" />
</classes>
</test>
</suite>
My pom.xml has dependency(xyz.jar) added. I can execute this suite from eclipse but fails when i try to execute from command-line(mac) with below error,
error: package test.sample does not exist
Any idea what the issue might be ?
My first guess is that you might not have a class defined like:
package test.sample;
public class TestX
{
...