Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

TestNG XML reportTest in Jira

"methodname" attribute

Summary field

"classname" attribute + "." + "methodname" attribute

Generic Test Definition custom field
groupslabels
"labels" attribute under the <attributes> tag, within some <test-method>, containing one or more labels delimited by space
labels
"test" attribute under the <attributes> tag, within some <test-method>, containing a Jira key of the Test issue
identification of Test issue key in Jira
"requirement" attribute under the <attributes> tag, within some <test-method>, containing a Jira key of requirement(s)link to requirement(s)

...

Consider running some Tests implemented in the following C# Java class.


Code Block
languagejava
titleexcerpt of Java Test class
package com.xpand.java;

import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.DataProvider;
import org.testng.Reporter;
import org.testng.reporters.XMLReporter;
import org.testng.ITestResult;
import com.xpand.annotations.Xray;

public class CalcTest {

    @BeforeSuite
    public void setUp() throws Exception {

    }

    @AfterSuite
    public void tearDown() throws Exception {
    }



    @DataProvider
    public Object[][] ValidDataProvider() {
        return new Object[][]{
            {  1, 2, 3 },
            {  2, 3, 4 },  // error or the data itself :)
            { -1, 1, 0 }
        };
    }


    @Test(dataProvider = "ValidDataProvider")
    @Xray(requirement = "CALC-1234", test = "CALC-1")
    public void CanAddNumbersFromGivenData(final int a, final int b, final int c)
    {
        Assert.assertEquals(Calculator.Add(a, b), c);
    }


	@Test
    @Xray(requirement = "CALC-1234", test = "CALC-2")
    public void CanAddNumbers()
    {
        Assert.assertEquals(Calculator.Add(1, 1),2);
        Assert.assertEquals(Calculator.Add(-1, 1),0);
        ITestResult result = Reporter.getCurrentTestResult();
        result.setAttribute("requirement", "CALC-1234");   // Xray will try to create a link to this requirement issue
        result.setAttribute("test", "CALC-2");             // Xray will try to find this Test issue and report result against it
        result.setAttribute("labels", "core addition");    // Xray will add this(ese) label(s) to the associated Test issue
    }


    @Test
    @Xray(requirement = "CALC-1235", labels = "core")
    public void CanSubtract()
    {
        Assert.assertEquals(Calculator.Subtract(1, 1), 0);
        Assert.assertEquals(Calculator.Subtract(-1, -1), 0);
        Assert.assertEquals(Calculator.Subtract(100, 5), 95);
    }


    @Test
    @Xray(requirement = "CALC-1236")
    public void CanMultiplyX()
    {
        Assert.assertEquals(Calculator.Multiply(1, 1), 1);
        Assert.assertEquals(Calculator.Multiply(-1, -1), 1);
        Assert.assertEquals(Calculator.Multiply(100, 5), 500);
    }


    @Test
    @Xray(requirement = "CALC-1237")
    public void CanDivide()
    {
        Assert.assertEquals(Calculator.Divide(1, 1), 1);
        Assert.assertEquals(Calculator.Divide(-1, -1), 1);
        Assert.assertEquals(Calculator.Divide(100, 5), 20);
    }


    @Test
    @Xray(test = "CALC-6")
    public void CanDoStuff()
    {
        Assert.assertNotEquals(true, true);
    }


}

In the first Test, Xray would try to find a Test with the key "CALC-10". If it does not exist, the Test won't be created.

The test would be linked to the Requirement with key "CALC-69", using the "tests" association, if the requirement exists.

If there is a requirement with the key "CALC-1", it would create the link to that requirement. If "CALC-1" corresponds to a Test issue, then "CALC_1" is ignored.

If the Category "CALC_1" does not map to either a requirement or a Test, it would be added to the Test as a label.

In the second Test, a Generic Test with the summary "CanSubtract" would be created.

The Test is only created if no Test with same Generic Test Definition already exists or if "CALC-2" does not correspond to a Test issue.

If there is a requirement with the key "CALC-2", it would create the link to that requirement.

If the Category "CALC_2" does not map to either a requirement or a Test, it would be added to the Test as a label.

...
}




In the first Test, we can see an example of a parameterized test using a data provider. Xray would try to find a Test with the same Generic Test Definition, if it does not find one then it will create a Test issue.

In the second Test, a Generic Test with the summary "CanAddNumbers" would be created.

The Test is only created if no Test with same Generic Test Definition already exists or if "CALC-2" does not correspond to a Test issue.

If there is a requirement with the key "CALC-1234", it would create the link to that requirement.

Additionaly, "core" and "addition" would be added to the Test as labels.


Info
titleLearn more
It's possible to use Java annotations to more easily mark the Test methods with the linked requirement(s), Test or with the labels you wish to add. Please have a look at the examples shown in Testing using TestNG in Java .
Code Block
languagejava
titleexcerpt of Java Test class
package com.xpand.java; import org.testng.Assert; import org.testng.annotations.Test; import org.testng.annotations.BeforeSuite; import org.testng.annotations.AfterSuite; import org.testng.annotations.DataProvider; import org.testng.Reporter; import org.testng.reporters.XMLReporter; import org.testng.ITestResult; import com.xpand.annotations.Xray; public class CalcTest { @BeforeSuite public void setUp() throws Exception { } @AfterSuite public void tearDown() throws Exception { } @DataProvider public Object[][] ValidDataProvider() { return new Object[][]{ { 1, 2, 3 }, { 2, 3, 4 }, // error or the data itself :) { -1, 1, 0 } }; } @Test(dataProvider = "ValidDataProvider") @Xray(requirement = "CALC-1234", test = "CALC-1") public void CanAddNumbersFromGivenData(final int a, final int b, final int c) { Assert.assertEquals(Calculator.Add(a, b), c); } @Test @Xray(requirement = "CALC-1234", test = "CALC-2") public void CanAddNumbers() { Assert.assertEquals(Calculator.Add(1, 1),2); Assert.assertEquals(Calculator.Add(-1, 1),0); ITestResult result = Reporter.getCurrentTestResult(); } @Test @Xray(requirement = "CALC-1235", labels = "core") public void CanSubtract() { Assert.assertEquals(Calculator.Subtract(1, 1), 0); Assert.assertEquals(Calculator.Subtract(-1, -1), 0); Assert.assertEquals(Calculator.Subtract(100, 5), 95); } @Test @Xray(requirement = "CALC-1236") public void CanMultiplyX() { Assert.assertEquals(Calculator.Multiply(1, 1), 1); Assert.assertEquals(Calculator.Multiply(-1, -1), 1); Assert.assertEquals(Calculator.Multiply(100, 5), 500); } @Test @Xray(requirement = "CALC-1237") public void CanDivide() { Assert.assertEquals(Calculator.Divide(1, 1), 1); Assert.assertEquals(Calculator.Divide(-1, -1), 1); Assert.assertEquals(Calculator.Divide(100, 5), 20); } @Test @Xray(test = "CALC-6") public void CanDoStuff() { Assert.assertNotEquals(true, true); } }


Status

The status of the Test Run will be set based on the Test case result:

Test Cases (NUnit3.0)


Test status

Failed

Error

FAIL

Passed

Success

PASS

Other Cases

Other Cases

TODO

...