JIRA Game – Show Me Your Unit Tests

Here’s a fun little game you can play with JIRA, Git, and Feature Branches.

Ideally, each Agile team should be creating unit tests for each story… but are they?

Well, let’s make it fun! 

Let’s make a game-show where a team and one of there stories is selected at random. Next we look at the commits on the JIRA (linked to revision control by the JIRA #), do the changes have unit tests on them?


package showMeYourUnitTest

import groovy.json.JsonSlurper
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response

class ShowMeYourUnitTest {
    def static jiraInstance = 'https://jira.REDACTED.DOMAIN'
    def fixVersion = '2019.08.11 Release'
def authString = 'Basic REDACTED'
def static teams = [ [name: 'TeamName1', teamId: 118], [name: 'Core Dump', teamId:110], [name: 'Segfalt', teamId:114], [name: 'Blue Screen', teamId:121], [name: 'Team122', teamId:122], [name: 'Team127', teamId:127], [name: 'Team124', teamId:124], [name: 'Team123', teamId:123], [name: 'Team126', teamId:126], [name: 'Team125', teamId:125], [name: 'Team133', teamId:133], [name: 'Team134', teamId:134], [name: 'Team136', teamId:136] ] public static void main(String[] args) { Random rnd = new Random() def teamIdx = rnd.nextInt(teams.size()) def team = teams[teamIdx] println "\nteam: name ${team.name}" OkHttpClient client = new OkHttpClient(); def myQuery = "project IN(PRJ1,PRJ2) AND team=${team.teamId} AND status=Done AND type NOT IN(Sub-task,22,\"Feature Request\") AND (fixVersion=\"${fixVersion}\" OR updatedDate > -30d)" def encodedQuery = java.net.URLEncoder.encode(myQuery, "UTF-8") Request request = new Request.Builder() .url("${jiraInstance}/rest/api/2/search?jql=${encodedQuery}") .get() .addHeader("Content-Type", "application/json") .addHeader("Accept", "application/json") .addHeader("Cache-Control", "no-cache") .addHeader("Authorization", authString ) .build(); Response response = client.newCall(request).execute(); println "\nJIRA Response code: ${response.code()}" def selectedIssueKey = '' if (response.code()==200) { String responseBodyString = response.body().string() JsonSlurper js = new JsonSlurper() def data = js.parseText(responseBodyString) println "\n\nTeam ${team.name}, Jira count: ${data.total}" data.issues.each{issue -> println "${issue.key}, ${issue.fields.issuetype.name}, ${issue.fields.summary}" } if (data.total>0) { def selectedIndex = new Random().nextInt(data.total) println "\n\nSelected issue" def selIssue = data.issues[selectedIndex] println "${selIssue.key}, ${selIssue.fields.issuetype.name}, ${selIssue.fields.summary}" selectedIssueKey = selIssue.key openSelectedIssue(selectedIssueKey) openIssues(encodedQuery) } else println "What? No issues in fix version? or updated recently?" } } def static openIssues(encodedQuery) { try { def url = "${jiraInstance}/issues/?jql=${encodedQuery}" Process p = Runtime.getRuntime().exec("\"/Program Files (x86)/Google/Chrome/Application/chrome.exe\" ${url}"); p.waitFor(); } catch (Exception e) { println("openIssues failed to launch chrome") } } def static openSelectedIssue(jiraNumber) { try { def url = "${jiraInstance}/browse/${jiraNumber}" Process p = Runtime.getRuntime().exec("\"/Program Files (x86)/Google/Chrome/Application/chrome.exe\" ${url}"); p.waitFor(); } catch (Exception e) { println("openSelectedIssue failed to launch chrome") } } }

Leave a Reply

Your email address will not be published.