I need to display test coverage by comparing two JQL query results
Asked by Dave Collins:

My effort is to run two JQL queries, that compare results and output a percentage.

eg

```
issueType = userStory AND created &gt;= 2015-09-01 AND created &lt;= 2015-12-31 AND project = project 1
```

vs

```
issueType = subTask AND created &gt;= 2015-09-01 AND created &lt;= 2015-12-31 AND project = project 1
```

With these results (my subTask is actually an issueType of Acceptance Test) I can see that query #1 returns 285 results and query #2 returns 245 results. Simple math shows me that I have 86.95% coverage. Great! Now how can I have this displayed on a Team Space in Confluence?

percent.png  
[](https://community.atlassian.com/t5/Confluence-questions/I-need-to-display-test-coverage-by-comparing-two-JQL-query/qaq-p/121457?attachment-id=3530){#link_119173f30a9638}  
[](/tnckb94959/attachments/tnckb94959/confluence-questions/20200/1/percent.png){#display_119173f30a9638_0}


Answers:
author: Doug Swartz
body: Using the equivalent of the JQL in my answer above, in my system I generated this graph:

Samplegraph.png

In my graph, the task issue type is a subtask of the Defect issue type. there are 5063 Defects, 874 of them have a task subtask.

I don't know how to do what you want in native Jira. I used a ScriptRunner plugin JQL function to enable this. What plugins to you have available?  
[](https://community.atlassian.com/t5/Confluence-questions/I-need-to-display-test-coverage-by-comparing-two-JQL-query/qaq-p/121457?attachment-id=1599){#link_119173f82933d3}  
[](/tnckb94959/attachments/tnckb94959/confluence-questions/20205/1/Samplegraph.png){#display_119173f82933d3_0}

comments: author: Dave Collins
body: Unfortunately, we're running the Cloud serviced JIRA. No Script Runner for me.


author: Doug Swartz
body: Are your subtasks, subtasks of the user stories which they test? If so, do you have the script runner plugin available?If so, you could do a query something like:

```
created &gt;= 2015-09-01 AND created &lt;= 2015-12-31 AND project = project 1 and (issueType = subtask or (issuetype = userstory and issueFunction not in hasSubtasks()))
```

Script runner is required to only get the userstories that don't have subtasks. There may be other plugins to do the same thing.

If you have a query that gets the subtasks and stories without subtasks, you can put it in a pie chart to see the percentages.

comments: author: Dave Collins
body: The subTasks should be children to the userStory. Q1 is pulling all userStory (equals 285) and Q2 pulls all subTasks (245). I need to compare those two query results as a percentage.


author: Doug Swartz
body: If you want to use one of the Jira gadgets to display percentage, you need to do a single query. I'm suggesting you query the subtasks, plus all the stories which don't have a subtask, in a single query. This will give you 245 subtasks and 40 user stories in the query for a total of 285. If you put that query into a Jira pie chart gadget and differentiate the pie slices by issuetype, you get a pie chart with the percentages you want. The query above does what you want in my Jira system. However, it relies on the presence of the ScriptRunner plugin.JQL function "issueFunction not in hasSubtasks()". If you have the ScriptRunner add-on, or another add-on which lets you query issues without subtasks, this will work.


author: Dave Collins
body: Updated with a screen shot.


Tags: jira