Customizing TestNG result xml

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Customizing TestNG result xml

ndk-2
I am using TestNG to run my test suites and the tests are kicked off
via Jenkins. I am using TestNG plugin in Jenkins. One of our
requirement is to add a custom attribute called 'critical' to testng-
results.xml

Current testng-result.xml

<testng-results skipped="0" failed="3" total="5" passed="2">
......
</testng-results>
Expected testng-result.xml

 <testng-results skipped="0" failed="3" total="5" passed="2"
critical="2">
    ......
 </testng-results>
I tried below in @Test just to see how setAttribute works, but it
didn't add any attribute to the test in testng-results.xml (not sure
what I am missing, I am running TestNG programatically and not through
command line). I am not sure if ITestResult.setAttribute would be
useful in my case because I guess it will add attribute at the test
level and I need to add attribute at the suite level. I also
implemented ITestListener but wasn't successful. Am I missing
anything, can someone point me in the right direction?

In testng-results.xml I don't see any critical tag or attribute in
testng-results.xml. I am using testng 6.5.1

TestNGRunner Class Running TestNG by code

XmlSuite suite = new XmlSuite();
suite.setName("Custom Report");
XmlTest test = new XmlTest(suite);
test.setName("customreport");
classes = new ArrayList<XmlClass>();
String [] runSuites = {"com.test.Testing"};
for(String asuite:runSuites)
  classes.add(new XmlClass(asuite));
test.setXmlClasses(classes);
List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.run();
com.test.Testing class

@Test
public void test() {
  System.out.println("running my test");
  ITestResult result = Reporter.getCurrentTestResult();
  result.setAttribute("critical", 10);
}

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Customizing TestNG result xml

Cédric Beust ♔-2
This question looks familiar, didn't I already answer it on StackOverflow?

-- 
Cédric




On Wed, May 9, 2012 at 8:11 AM, ndk <[hidden email]> wrote:
I am using TestNG to run my test suites and the tests are kicked off
via Jenkins. I am using TestNG plugin in Jenkins. One of our
requirement is to add a custom attribute called 'critical' to testng-
results.xml

Current testng-result.xml

<testng-results skipped="0" failed="3" total="5" passed="2">
......
</testng-results>
Expected testng-result.xml

 <testng-results skipped="0" failed="3" total="5" passed="2"
critical="2">
   ......
 </testng-results>
I tried below in @Test just to see how setAttribute works, but it
didn't add any attribute to the test in testng-results.xml (not sure
what I am missing, I am running TestNG programatically and not through
command line). I am not sure if ITestResult.setAttribute would be
useful in my case because I guess it will add attribute at the test
level and I need to add attribute at the suite level. I also
implemented ITestListener but wasn't successful. Am I missing
anything, can someone point me in the right direction?

In testng-results.xml I don't see any critical tag or attribute in
testng-results.xml. I am using testng 6.5.1

TestNGRunner Class Running TestNG by code

XmlSuite suite = new XmlSuite();
suite.setName("Custom Report");
XmlTest test = new XmlTest(suite);
test.setName("customreport");
classes = new ArrayList<XmlClass>();
String [] runSuites = {"com.test.Testing"};
for(String asuite:runSuites)
 classes.add(new XmlClass(asuite));
test.setXmlClasses(classes);
List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.run();
com.test.Testing class

@Test
public void test() {
 System.out.println("running my test");
 ITestResult result = Reporter.getCurrentTestResult();
 result.setAttribute("critical", 10);
}

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Customizing TestNG result xml

ndk-2
You did and I replied too :-) I also included my reply in the question
here.

You mentioned that these attributes will be present in testng-
results.xml in a section of their own and not as an attribute in
<testng-results>. Unfortunately I don't see any of that in testng-
results.xml.

I am desperate for an answer that's why the double post on SO and
google groups.

Thanks!

In testng-results.xml I don't see any critical tag

On May 9, 1:02 pm, Cédric Beust ♔ <[hidden email]> wrote:

> This question looks familiar, didn't I already answer it on StackOverflow?
>
> --
> Cédric
>
>
>
>
>
>
>
> On Wed, May 9, 2012 at 8:11 AM, ndk <[hidden email]> wrote:
> > I am using TestNG to run my test suites and the tests are kicked off
> > via Jenkins. I am using TestNG plugin in Jenkins. One of our
> > requirement is to add a custom attribute called 'critical' to testng-
> > results.xml
>
> > Current testng-result.xml
>
> > <testng-results skipped="0" failed="3" total="5" passed="2">
> > ......
> > </testng-results>
> > Expected testng-result.xml
>
> >  <testng-results skipped="0" failed="3" total="5" passed="2"
> > critical="2">
> >    ......
> >  </testng-results>
> > I tried below in @Test just to see how setAttribute works, but it
> > didn't add any attribute to the test in testng-results.xml (not sure
> > what I am missing, I am running TestNG programatically and not through
> > command line). I am not sure if ITestResult.setAttribute would be
> > useful in my case because I guess it will add attribute at the test
> > level and I need to add attribute at the suite level. I also
> > implemented ITestListener but wasn't successful. Am I missing
> > anything, can someone point me in the right direction?
>
> > In testng-results.xml I don't see any critical tag or attribute in
> > testng-results.xml. I am using testng 6.5.1
>
> > TestNGRunner Class Running TestNG by code
>
> > XmlSuite suite = new XmlSuite();
> > suite.setName("Custom Report");
> > XmlTest test = new XmlTest(suite);
> > test.setName("customreport");
> > classes = new ArrayList<XmlClass>();
> > String [] runSuites = {"com.test.Testing"};
> > for(String asuite:runSuites)
> >  classes.add(new XmlClass(asuite));
> > test.setXmlClasses(classes);
> > List<XmlSuite> suites = new ArrayList<XmlSuite>();
> > suites.add(suite);
> > TestNG tng = new TestNG();
> > tng.setXmlSuites(suites);
> > tng.run();
> > com.test.Testing class
>
> > @Test
> > public void test() {
> >  System.out.println("running my test");
> >  ITestResult result = Reporter.getCurrentTestResult();
> >  result.setAttribute("critical", 10);
> > }
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to
> > [hidden email].
> > For more options, visit this group at
> >http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

SPS
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Customizing TestNG result xml

SPS
In reply to this post by ndk-2
Hello all,
I have a same question. I have

On Wednesday, May 9, 2012 at 10:11:54 AM UTC-5, ndk wrote:
I am using TestNG to run my test suites and the tests are kicked off
via Jenkins. I am using TestNG plugin in Jenkins. One of our
requirement is to add a custom attribute called 'critical' to testng-
results.xml

Current testng-result.xml

<testng-results skipped="0" failed="3" total="5" passed="2">
......
</testng-results>
Expected testng-result.xml

 <testng-results skipped="0" failed="3" total="5" passed="2"
critical="2">
    ......
 </testng-results>
I tried below in @Test just to see how setAttribute works, but it
didn't add any attribute to the test in testng-results.xml (not sure
what I am missing, I am running TestNG programatically and not through
command line). I am not sure if ITestResult.setAttribute would be
useful in my case because I guess it will add attribute at the test
level and I need to add attribute at the suite level. I also
implemented ITestListener but wasn't successful. Am I missing
anything, can someone point me in the right direction?

In testng-results.xml I don't see any critical tag or attribute in
testng-results.xml. I am using testng 6.5.1

TestNGRunner Class Running TestNG by code

XmlSuite suite = new XmlSuite();
suite.setName("Custom Report");
XmlTest test = new XmlTest(suite);
test.setName("customreport");
classes = new ArrayList<XmlClass>();
String [] runSuites = {"com.test.Testing"};
for(String asuite:runSuites)
  classes.add(new XmlClass(asuite));
test.setXmlClasses(classes);
List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.run();
com.test.Testing class

@Test
public void test() {
  System.out.println("running my test");
  ITestResult result = Reporter.getCurrentTestResult();
  result.setAttribute("critical", 10);
}

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
SPS
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Customizing TestNG result xml

SPS
In reply to this post by ndk-2
Hello all,
I have same question. I am using TestNG plugin in Jenkins also I overrode generate report method. testing-results.xml generated by overriding generate report method
has
<testng-results skipped="0" failed="0" total="0" passed="0"> which is not correct also test does not include all the methods from it's test class. It only includes
<test-method status="PASS" signature="beforeClass ...">
Please advise

Thanks


On Wednesday, May 9, 2012 at 10:11:54 AM UTC-5, ndk wrote:
I am using TestNG to run my test suites and the tests are kicked off
via Jenkins. I am using TestNG plugin in Jenkins. One of our
requirement is to add a custom attribute called 'critical' to testng-
results.xml

Current testng-result.xml

<testng-results skipped="0" failed="3" total="5" passed="2">
......
</testng-results>
Expected testng-result.xml

 <testng-results skipped="0" failed="3" total="5" passed="2"
critical="2">
    ......
 </testng-results>
I tried below in @Test just to see how setAttribute works, but it
didn't add any attribute to the test in testng-results.xml (not sure
what I am missing, I am running TestNG programatically and not through
command line). I am not sure if ITestResult.setAttribute would be
useful in my case because I guess it will add attribute at the test
level and I need to add attribute at the suite level. I also
implemented ITestListener but wasn't successful. Am I missing
anything, can someone point me in the right direction?

In testng-results.xml I don't see any critical tag or attribute in
testng-results.xml. I am using testng 6.5.1

TestNGRunner Class Running TestNG by code

XmlSuite suite = new XmlSuite();
suite.setName("Custom Report");
XmlTest test = new XmlTest(suite);
test.setName("customreport");
classes = new ArrayList<XmlClass>();
String [] runSuites = {"com.test.Testing"};
for(String asuite:runSuites)
  classes.add(new XmlClass(asuite));
test.setXmlClasses(classes);
List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.run();
com.test.Testing class

@Test
public void test() {
  System.out.println("running my test");
  ITestResult result = Reporter.getCurrentTestResult();
  result.setAttribute("critical", 10);
}

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Loading...