---
title: "Advanced JQL Examples for Organizing & Planning Test Cases"
canonical: "https://docs.getxray.app/space/XRAYCLOUD/656474150/Advanced%20JQL%20Examples%20for%20Organizing%20%26%20Planning%20Test%20Cases"
format: markdown
---
> Macro (rw-ui-expands-macro)
> 
> > Macro (rw-expand)
> 
> > Macro (toc)


# Introduction

> ℹ️ **JQL Features in Jira Cloud**
> ℹ️ 
> ℹ️ Atlassian has been improving JQL support in Cloud but there still may be discrepancies in experience if you are coming from Jira Data Center.

Whether you are leveraging Xray’s [Dynamic Test Plans](https://docs.getxray.app/space/XRAYCLOUD/44565153/Test+Plan#Configuring-a-Test-Plan-with-a-Saved-Filter-(-Xray-Enterprise-Only-)) or just need a JQL filter/statement to help with selecting [Tests](https://getxraydocs.atlassian.net/wiki/spaces/XRAYCLOUD/pages/44565156) for [Test Sets](https://getxraydocs.atlassian.net/wiki/spaces/XRAYCLOUD/pages/44565163), [Test Executions](https://getxraydocs.atlassian.net/wiki/spaces/XRAYCLOUD/pages/44565117), [Reports/Gadgets](https://getxraydocs.atlassian.net/wiki/spaces/XRAYCLOUD/pages/44566250), etc., you will likely encounter advanced JQL use cases that go beyond single-factor expressions like “label = 'regression'” or “component in (A, B)”. 

In this article, we will cover two possible solution paths for a similar set of JQL goals: 

- [Xray JQL Functions](https://docs.getxray.app/space/XRAYCLOUD/44565225/Enhanced+Querying+with+JQL) (beta, requires opt-in, **for scenarios focused on Xray entities**);
- <u>[ScriptRunner app](https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?hosting=cloud&tab=overview)</u><u>,</u> specifically “[Enhanced Search](https://docs.adaptavist.com/sr4jc/latest/features/scriptrunner-enhanced-search)” feature (**wider scope**; you may also be able to implement this using another app with similar capabilities).

# Implementation Examples

All the “identify Tests that cover…” use cases rely on 

- the “requirementTests” Xray JQL Function. Sample syntax:

```
issuetype = 'Test' and key in requirementTests('Coverable work item key or saved filter')
```

or

- the “linkedIssuesOf” ScriptRunner Function. Sample syntax:

```
issueFunction in linkedIssuesOf("JQL to identify work items that tests are linked to", "is tested by")
```


## Identifying Tests that Cover Requirements Assigned to a Specific Component

### **Xray JQL Functions**

1. Save a JQL filter (e.g., "stories_for_login_component"). Sample syntax:
2. Use the JQL:
  as e.g., a **statement directly** in a Test Set or a static Test Plan, or **save it as a filter** to use in a Dynamic Test Plan (Xray Enterprise only).

### **ScriptRunner Enhanced Search**

In *Apps* > *ScriptRunner Enhanced Search (Figure 1),* create a filter (e.g., "tests_for_login_component") for the following JQL query. To filter by status, just add the clause "... and status = '...' ".

**Sample JQL**

```
issueFunction in linkedIssuesOf("project = CALC and issuetype = "Story" and Component = 'login'", "is tested by")
```

![Figure 1 - ScriptRunner](media://6cedbcc7-90a4-4200-b256-cb8b0e3dec47)

## Identifying Tests that Cover High-Priority Requirements

### **Xray JQL Functions**

1. Save a JQL filter (e.g., "high_priority_requirements"). Sample syntax:
2. Use the JQL
  as e.g. a **statement directly** in a Test Set or a static Test Plan, or **save it as a filter** to use in a Dynamic Test Plan (Xray Enterprise only).

### **ScriptRunner Enhanced Search**

In *Apps* > *ScriptRunner Enhanced Search *(Figure 2), create a filter (e.g., "tests_for_stories_high_priority") for the following JQL query. To filter by status, just add the clause "... and status = '...' ".

**Sample JQL**

```
issueFunction in linkedIssuesOf("project = CALC and issuetype = "Story" and Priority  = 'High'", "is tested by")
```

![Figure 2 - ScriptRunner](media://cd36f9c2-9986-4320-a3d3-322716c66c08)

## Identifying Tests that Cover "Risky" Requirements

### Context

A tester wants to identify all the Tests that cover Requirements having a certain risk level associated with them, set using a specific custom field.

> ℹ️ Organizations can implement risk management in different ways.

### **Xray JQL Functions**

1. Save a JQL filter (e.g., "medium_risk_requirements"). Sample syntax:
2. Use the JQL
  as e.g. a **statement directly** in a Test Set or a static Test Plan, or **save it as a filter** to use in a Dynamic Test Plan (Xray Enterprise only).

### **ScriptRunner Enhanced Search**

In *Apps* > *ScriptRunner Enhanced Search* (Figure 3), create a filter (e.g., "tests_for_stories_medium_risk") for the following JQL query.

**Sample JQL**

```
issueFunction in linkedIssuesOf("project = CALC and issuetype = "Story" and 'RiskLevel' ~ 'L2: Medium'", "is tested by")
```

![Figure 3 - ScriptRunner](media://3a81832f-bb66-472f-9984-2050c073dd62)

## Identifying Tests that Cover Requirements for a Specific Sprint

### Context

- A tester wants to identify all the Tests that matter to the sprint.
- We will share an example that can be extended for other methodologies using different JQL Queries. Still, for this one, we are considering the Agile Scrum methodology.

In this example (Figure 4), we have an active Sprint named "CALC Sprint 1" with two user stories, each one covered by some Test(s).

![Figure 4 - Example](media://37715cd4-bc72-475d-a5c8-83ffbdc5b8fa)

### **Xray JQL Functions**

1. Save a JQL filter (e.g., "stories_for_calc_sprint1"). Sample syntax:
2. Use the JQL
  as e.g. a **statement directly** in a Test Set or a static Test Plan or **save it as a filter** to use in a dynamic Test Plan.

### **ScriptRunner Enhanced Search**

In *Apps* > *ScriptRunner Enhanced Search* (Figure 5), create a JQL Filter named "tests_for_calc_sprint1" that lists all Tests covering user stories in the sprint named "CALC Sprint 1".

**Sample JQL**

```
issueFunction in linkedIssuesOf("project = CALC and issuetype = "Story" and sprint = "CALC Sprint 1" ", "is tested by")
```

![Figure 5 - ScriptRunner](media://b2cebe8c-b355-47e2-919f-a53a372b71eb)

## Identifying Tests that Cover Requirements Assigned to the Current Open/Active sprints

### **Xray JQL Functions**

1. Save a JQL filter (e.g., "stories_for_current_sprints"). Sample syntax:
2. Use the JQL
  as e.g. a **statement directly** in a Test Set or a static Test Plan or **save it as a filter** to use in a dynamic Test Plan.

### **ScriptRunner Enhanced Search**

In *Apps* > *ScriptRunner Enhanced Search* (Figure 6), create a filter (e.g., "tests_for_current_sprints") for the following JQL query.

**Sample JQL**

```
issueFunction in linkedIssuesOf("project = CALC and issuetype = "Story" and sprint in openSprints() ", "is tested by")
```

![Figure 6 - ScriptRunner](media://ae31c977-e543-4ed1-9796-ef49debc2cb3)

## Identifying Tests that Cover Requirements for the Current Version

### **Xray JQL Functions**

1. Save a JQL filter (e.g., "requirements_for_calc_v2"). Sample syntax:
  or
2. Use the JQL
  as e.g. a **statement directly** in a Test Set or a static Test Plan or **save it as a filter** to use in a dynamic Test Plan.

### **ScriptRunner Enhanced Search**

In *Apps* > *ScriptRunner Enhanced Search* (Figure 7), create a filter (e.g., "tests_for_calc_v2") for the following JQL query.

**Sample JQL**

```
issueFunction in linkedIssuesOf('project = CALC and issuetype in ("Story", "Epic") and fixVersion = "v2.0"', "is tested by")
```

or

```
issueFunction in linkedIssuesOf('project = CALC and issuetype in ("Story", "Epic") and fixVersion = earliestUnreleasedVersion(CALC) ', "is tested by")
```

![Figure 7 - ScriptRunner](media://36fa6bb4-0bd5-4e49-b86b-3f814af23dd2)

## Identifying Tests that Cover Requirements from Previous Versions

This use case is similar to the previous example; we just need to slightly adjust the query.

### **Xray JQL Functions**

1. Save a JQL filter (e.g., "requirements_for_previous_releases"). Sample syntax:
  or
2. Use the JQL
  as e.g. a **statement directly** in a Test Set or a static Test Plan or **save it as a filter** to use in a dynamic Test Plan.

### **ScriptRunner Enhanced Search**

In *Apps* > *ScriptRunner Enhanced Search* (Figure 8) create a filter (e.g., "tests_for_previous_releases") for the following JQL query.

**Sample JQL**

```
issueFunction in linkedIssuesOf('project = CALC and issuetype in ("Story", "Epic")) and fixVersion in ("1.0", "1.1", "1.2")', "is tested by")
```

or

```
issueFunction in linkedIssuesOf('project = CALC and issuetype in ("Story", "Epic")) and fixVersion in releasedVersions()', "is tested by")
```

![Figure 8 - ScriptRunner](media://da9627b6-1ad4-4c3a-bc95-df23f7043921)

> Macro (rw-ui-expands-macro)
> 
> > Macro (rw-expand)
> 
> If you have questions or technical issues, please [contact the Support team via the Customer Portal (Jira service management)](https://jira.getxray.app/servicedesk/customer/portal/2/user/login?destination=portal%2F2%2Fcreate%2F28) or [send us a message using the in-app chat](https://getxraydocs.atlassian.net/wiki/spaces/XRAYCLOUD/pages/44577312).