Adding Test Set to an Issue.
Asked by Daniel Zhekov:

Hello, Community.  
I am having trouble to make full automation between gitlab and jira with xray addon.  
I managed to upload the junit through xray rest api after that create a Test set and add the tests to that test set.  
Problem is now I want to add the test set to the opened issue and I know I can do that through the GUI. Open your issue -\> Add test -\> Tests from Test Set, but how I can do that with the rest api, so I can do it from the pipeline.


Answers:
author: Stefan Salzl
body: Hi [@Daniel Zhekov](/t5/user/viewprofilepage/user-id/5582110)

as you can see in the following link leading to xray docu the test coverage of an issue can simply be set with native Jira Issue Linking (tests - tested by)

<https://docs.getxray.app/display/XRAY/Test+Coverage#TestCoverage-AssociateTestsorTestSets(usingplainJiraissueLinks>)

So as far as you?ve got all testcase?s issue keys you could just link the to the requirement/covered issue. (as far as you are creating a seperate test set for each covered issue I guess you could even only link the test set and the test cases will be set in the issue as covering tests - didn?t test this use case though). Here is the api docu for linking issue - please notice that it?s not done via xray rest api but native jira rest api:

<https://confluence.atlassian.com/jirakb/how-to-use-rest-api-to-add-issue-links-in-jira-issues-939932271.html>

Hope I got your requirement wrong and this was helpful. Please let us know if you have any further questions.

Best  
Stefan

comments: author: Daniel Zhekov
body: I don't want to create test set for each test. I want to have a single test set that contains all the tests, so i don't have to link each individual test. When I use the rest api to link it the test coverage does not populate. The link is there, but the coverage is not shown.


author: Stefan Salzl
body: Not a test set for each test. I meant a test set for each requirement that should be covered by tests.

Let's take one step back and wrap it up to be sure I got everything clear.

There is a requirement that should be covered by some tests lets call that REQ-1.

You ran 3 autmated tests. The results were imported, executions created and also 3 test issues, let's say TEST-1,2,3.

Furthermore a test set is created consisting of those 3 test cases.

Was that correct so far?

For further investigation:

Could you share more insights of what you were trying? How did you link the issues? Could you please also share some screenshots of your issues? Does the coverage appear when you add the issues manually? Are the links created when you add the tests manually?

Best  
Stefsn


author: Daniel Zhekov
body: First of all: Thank you for your time.  
Now I played some more with it to see exactly how everything works. So basically My tests TEST-1,2,3 are saved in the xray test as an individual tests and the Test Execution says for that execution which tests have passed and which haven't. So what I am trying to do is to link that specific execution to REQ-1, so the results are displayed under test coverage.   
The tricky part is that the same TEST-1,2,3 should be able to run for REQ-2,3...N and report an Test execution for the specific requirement.  

All that being done inside a GitLab's pipeline.   

I hope that my explanation is clear ?


author: Stefan Salzl
body: Hi [@Daniel Zhekov](/t5/user/viewprofilepage/user-id/5582110)

I tested this - technically it works exactly as I described. As long as a test case is within a test execution - when the test case is linked with "TEST" linktype to a requirement AND the issuetype of the requirement is configured as a coverable issue (in xray settings) - the coverage is shown (a requirement will always show test executions where its own tests were run).

I did the follwing POST call:

{{baseURL}}/rest/api/2/issueLink

JSON Payload:  

```
{

    "type": {

        "name": "Tests"

    },

    "inwardIssue": {

        "key": "XRAYEV-14"

    },

    "outwardIssue": {

        "key": "XRAYEV-19"

    },

    "comment": {

        "body": "Linked test issue!"

    }

}
```

wheras "XRAYEV-19" is the covered Story and "XRAYEV-14" is my test case.

Results in:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/345535i49ECAFB051B1EE68/image-size/large?v=v2&px=999 "image.png")

So I would recommend to re-check the xray settings:

- is your issue type (requirement) configured in the xray settings "Issue type mapping"

- please also check the requirements coverage section in the xray settings:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/345532iAE9E2B74EC5A7EE9/image-size/large?v=v2&px=999 "image.png")

As mentioned it?s simply a rest api call so it can be executed from gitlab pipeline.

Please share everything you?ve done so far (calls, payloads, etc) and also screenshots to know where you ended up and got stuck.

Best  
Stefan


author: Marc - Devoteam
body: Hi [@Daniel Zhekov](/t5/user/viewprofilepage/user-id/5582110)

I don't think this is possible in the xray API. To be sure my suggestion is to ask your question at Xray support.

Let me know what comes out of it, I would like to know as well.

comments: author: Daniel Zhekov
body: Thanks for you support.


author: Daniel Zhekov
body: Update:  
I did ask the xray support and yes. Having the test execution linked in a way that shows results in test coverage is not possible. So to see the coverage you have to click on the linked test execution and check it there.


Tags: data-center

gitlab

jira-data-center

xray