---
title: "Working with Test Environments"
canonical: "https://docs.getxray.app/space/XRAY/301665065/Working%20with%20Test%20Environments"
format: markdown
---
> ℹ️ "Test Environment" is a concept introduced in Xray v2.
> ℹ️ 
> ℹ️ Here is a [short video](https://www.youtube.com/watch?v=fokqOe92OQM) that explains Test Environments and how you can use them.


> Macro (toc)

# <span style="color: #000000">What is a Test Environment</span>

<span style="color: #000000">Generically speaking, a test environment is an environment that contains all necessary elements, including the SUT, so you can perform testing on it.</span>

<span style="color: #000000">Depending on your context, a test environment may represent:</span>

- <span style="color: #000000">a testing stage (e.g. "development", "staging", "preproduction", "production")</span>
- <span style="color: #000000">a device model or device operating system (e.g. "Android", "iOS")</span>
- <span style="color: #000000">an operating system (e.g. "Windows", "macOS", "Linux")</span>
- <span style="color: #000000">browser (e.g. "Edge", "Chrome", "Firefox")</span>

<span style="color: #000000">Thus, semantics of what a "Test Environment" represents depends on your specific context.</span>


> ℹ️ **Please note**
> ℹ️ 
> ℹ️ <span style="color: #000000">**In Xray, Test Environments are focused on the execution aspect, providing the means to schedule tests and **</span><u><span style="color: #000000">**analyze**</span></u><span style="color: #000000">** their results in different environments.**</span>
> ℹ️ 
> ℹ️ <span style="color: #000000">Thus, they're explicitly </span><u><span style="color: #000000">associated with Test Execution issues.</span></u>


# Benefits of using Test Environments

- avoid duplication of Tests, whenever you have to run the same test on different environments
- ability to track the latest status of tests on different environments
- ability to track coverage on each environment
- ability to track overall coverage, considering the coverage/results on each environment
- ability to perform reporting, including traceability, per each environment or globally (i.e. considering all results on all different environments)

# <span style="color: #000000">Test Environments in Xray at a glance</span>

<span style="color: #000000">The current status of a Test is generally calculated by looking at the Test's last execution (more detail </span>[here](https://getxraydocs.atlassian.net/wiki/spaces/XRAY/pages/301698037)<span style="color: #000000">). However, this does not work well if you execute the same Test in two different test environments (e.g., devices) and you want the two results to be consolidated. </span>

<span style="color: #000000">Within a Test Execution, you may specify the </span>**<span style="color: #000000">Test Environment</span>**<span style="color: #000000">(s) where the tests will be executed in the respective attribute. A Test Environment is similar to a label, but Xray has special logic to deal with it.</span>

<span style="color: #000000">If you use Test Environments, you may reuse the same Test for multiple test environments and create Test Executions for each one. If you don't use Test Environments and you want to track tests for multiple environments (e.g., devices), then the only way to do it is to create multiple tests, one per each test environment.</span>

<span style="color: #000000">Let's say that you have executions for two Test Environments: "Android" and "iOS". The test is considered as PASS only if the </span>**latest** <span style="color: #000000">executions for Android and iOS are </span>**<span style="color: #000000">both</span>**<span style="color: #000000"> PASS; otherwise, it will be FAIL.</span>


> Macro (gliffy)


<span style="color: #000000">Note: If you don't use Test Environments, then only the latest result matters for assessing the current status of the Test.</span>

# <span style="color: #000000">How it works</span>

<span style="color: #000000">Let's say we have a Test being executed two times. We will start by creating Test Executions TE1 and TE2.</span>

<span style="color: #000000">TE2 will be executed after TE1, so TE1 is considered older.</span>

<span style="color: #000000">Below are example scenarios and shows how the overall, </span>**<u><span style="color: #000000">consolidated</span></u>**<u><span style="color: #000000"> </span></u>**<u><span style="color: #000000">status</span></u>**<span style="color: #000000"> of the Test is calculated in each case.</span>

<span style="color: #000000">If you have a mix of Test Executions (i.e., with and without Test Environment as in scenario D), it will be treated the same way as scenarios A, B, and C.</span>


| **Scenario** | **Test Environment(s) of TE 1** | **Test Environment(s) of TE 2** | **Test run status in TE1** | <span style="color: #000000">**Test run status in TE2**</span> | **Calculated value for the overall, consolidated status of the Test (i.e. for the "All Environments")** | **Other** |
| --- | --- | --- | --- | --- | --- | --- |
| **A** | Android | iOS | PASS | PASS | <span style="color: #339966">**PASS**</span> | The test will be considered to be PASS in both Android and iOS environments. |
| **B** | iOS | iOS | PASS | FAIL | <span style="color: #ff0000">**FAIL**</span> | The test will be considered to be FAIL in iOS. |
| **C** | iOS | iOS | FAIL | PASS | <span style="color: #339966">**PASS**</span> | The test will be considered to be PASS in iOS. |
| **D** | iOS | - | FAIL | PASS | <span style="color: #ff0000">**FAIL**</span> | The test will be considered to be FAIL in iOS and PASS for the empty environment. |
| **E** | - | - | PASS | FAIL | <span style="color: #ff0000">**FAIL**</span> | The test will be considered to be FAIL for the empty environment. |
| **F** | - | - | FAIL | PASS | <span style="color: #339966">**PASS**</span>** ** | The test will be considered to be PASS for the empty environment. |

> ℹ️ **Please note**
> ℹ️ 
> ℹ️ The *empty* Test Environment is treated similarly to any other environment having a well-defined name.


# How to use

Whenever creating a Test Execution, you must set the Test Environment in which the execution will be executed. You can use this field as a simple label: just add the environment or reuse a previously created one.

Please see some important [Tips and Recommendations](#WorkingwithTestEnvironments-TipsandRecommendations) ahead.


**Creating a Test Execution**


![image](media://eae60b60-3936-4e04-b191-f6e92144dd47)

*Test Execution for “android” Test Environment*


![image](media://f6751720-c104-4515-b53c-7d1732e1f3b0)

*Test Execution for “ios” Test Environment*


**Tracking the results on different environments**

The Test Environments column is shown in your Test Runs table so you can distinguish each execution of the Test between the different environments.

This information can be seen in the Test issue screen (see next screenshot) or in other places that show a list of Test Runs (e.g. Test Plan issue screen).


![image](media://92a3ce25-e3cf-4dc3-a392-e61f880343fd)

*The same test has been executed in both Test Environments (a Test Execution per Test Environment).*


**Analyzing the impact of the results on different environments**

Results obtained for Test Environments will impact coverage.

Considering the previous screenshot, the "Requirement Status" custom field for the Test issue will show <span style="color: #ff0000">**NOK**</span> because the Test has failed for one of the environments. This information is <u>independent</u> of the environment picker below within the "Test Coverage" section, which in turn is used to calculate the coverage on request for the selected scope, showing it on the right side along with the corresponding test results.

![image](media://0c74619c-4d17-4807-a089-16b59217730d)


If you want to analyze the coverage for the requirement (e.g. "story") and show the latest results on that environment, just use the picker on the "Test Coverage" section. As seen ahead, this will produce different results because different results were obtained in different environments. 

> Macro (inline-media-image)

> Macro (inline-media-image)



<span style="color: #000000">Please check </span>[<span style="color: #000000">Coverage Analysis</span>](https://getxraydocs.atlassian.net/wiki/spaces/XRAY/pages/301662486)<span style="color: #000000"> to learn more about coverage analysis possibilities.</span>


<span style="color: #000000">It is also possible to analyze testing thoroughly considering Test Environments; t</span><span style="color: #000000">his analysis can be done using the </span>[<span style="color: #000000">Requirement Traceability Report</span>](https://getxraydocs.atlassian.net/wiki/spaces/XRAY/pages/301699901)<span style="color: #000000"> or the </span>[<span style="color: #000000">Overall Coverage Report</span>](https://getxraydocs.atlassian.net/wiki/spaces/XRAY/pages/301699454)<span style="color: #000000">, among others.</span>

<span style="color: #000000">The exact behavior upon choosing a specific Test Environment depends on the report itself but, either explicitly or implicitly, Test Runs will be filtered by the selected Test Environment and reports will reflect it.</span>


![image](media://f94c9a6a-bb4b-46e9-886c-4bfeabf3a5c3)

*Traceability Report being used to analyze the results on the "edge" test environment.*


![image](media://6d6b81bd-6017-4ce2-8ab4-31fb4d3a2d75)

*Traceability Report being used to analyze the results on the "chrome" test environment.*


![image](media://8060c190-346b-49f4-aa3f-636c292a5e4d)

*Analyzing coverage of "requirements" on the "edge" test environment.*


![image](media://6157f6cf-5bec-45be-ab42-6610075b8f3e)

*Analyzing coverage of "requirements" on the "chrome" test environment.*


# Using multiple environments at the same time

Sometimes, you may have multiple categorizations for a given environment; in theory, you can think as it being something multidimensional.

Consider a very basic example: whenever performing web/UI based testing you will be using a browser and an operating system and you may want to analyze the results per a browser perspective or per an operating system perspective.


**The recommended way to deal with environments having multiple dimensions is to treat each dimension (e.g. browser name, operating system name) individually. In other words, add the values of each dimension to the "Test Environments" field separately.**

![image](media://09bde4ea-da3a-4639-85a7-949c6ed04a4a)


Whenever you assign "mac" and "edge" to the Test Environments of a given Test Execution, it's equivalent to saying that your Test Run is scheduled for/was run in the "mac" and also in the "edge" environment.

This approach will limit the number of environments to the total number of possible values for each dimension, as opposed to having *<number_of_values_dimension_1>***<number_of_values_dimension_2>**... environments.

The drawback of this solution is that you won't be able to analyze the results for an environment tagged as "mac" and "edge" at the same time, for example; you can just analyze results from a specific dimension.


> ℹ️ **To have in mind**
> ℹ️ 
> ℹ️ One way to deal with these kinds of environments would be to flatten them and treat them as usual, i.e. you could name the environment such as “windows_edge” or “mac_chrome” but…
> ℹ️ 
> ℹ️ - You could have a ton of composed environments which wouldn’t be manageable at all
> ℹ️ - You couldn’t analyze coverage just from the perspective of one of those variables (e.g. “mac” or “edge”); you would be restricted to analyze it from the perspective of the composed environment

## How to use

Assign each environment (e.g. name of operation system, name of browser vendor) as you do for a single environment; in other words, just add the multiple environment names as <u>multiple, distinct labels</u>.


**Whenever creating a Test Execution (e.g. from a Test Plan)**

![image](media://45a3d683-cdde-4ff8-af4c-66ee50556c7a)


**Whenever updating an existing Test Execution**

![image](media://e43b26bb-d085-44cf-ab2a-65f8dc1441d1)


## Example

**<u>Test executed in the context of Test Execution assigned to several environments at the same time</u>**

1. windows, chrome (fail)
2. windows, edge (pass)
3. mac, edge (pass)


![image](media://29a6a804-6a9e-49d4-8d99-2bc4d2f9bc96)


The calculated status of the test, per Test environment, will be the following.

|  | **Status** | **Why?** |
| --- | --- | --- |
| **windows** | **<span style="color: #008000">PASS</span>** | due to the last result obtained in "windows" environment on CALC-5262 |
| **mac** | **<span style="color: #008000">PASS</span>** | due to the last result obtained in the "mac" environment on CALC-5263 |
| **chrome** | **<span style="color: #ff0000">FAIL</span>** | due to the last result obtained in "chrome" environment on CALC-5261 |
| **edge** | **<span style="color: #008000">PASS</span>** | due to the last result obtained in "edge" environment on CALC-5263 |
| **"All Environments"**<br>**(if analyzing the status of the test without identifying a specific environment)** | **<span style="color: #ff0000">FAIL</span>** | as the last result for one of the environments ("chrome") was FAIL (i.e. on CALC-5261) |


# Advanced

## Test Environments and the TestRunStatus custom field

The "TestRunStatus" custom field is associated with Test issues and can be used to provide information about the latest status of your test; more info [here](https://getxraydocs.atlassian.net/wiki/spaces/XRAY/pages/301474590).

This custom field calculates the status of the test for "all environments" (i.e. the consolidated status), giving you a high-level view; it cannot be configured to show the status for a specific environment.

Internally, this field will store the status of the test for all possible scopes, which besides other things includes the information about the status in all different environments.


> ℹ️ If you start using Test Environments in your Test Executions, then it's not only your test status calculation that will change (i.e. the one stored in the TestRunStatus custom field). All custom fields that depend on it (e.g., Requirement status, Test Sets status) will change. Consequently, the requirement coverage calculation and all associated charts/gadgets are also affected.

# Tips and Recommendations

## Do's

- Use Test Environments only if you want to run the **same** Test case in different environments and track results per each environment.
- Simplify the names of Test Environments (i.e. lowercase it, shorten it)
  - Example: macOS => mac
- Evaluate if you really need to assign multiple environments at the same time; using just one is preferable if you can afford that simplicity


> ℹ️ **Learn more**
> ℹ️ 
> ℹ️ For advanced Test Environment management capabilities, please check our [Integration with Apwide Golive](https://getxraydocs.atlassian.net/wiki/spaces/XRAY/pages/301468504).

## Don'ts

- Don't create thousands of Test Environments as it will harden their usage and add some performance overhead
- Don't try to do data-driven testing using Test Environments; they're not tailored for that


> ℹ️ **Please note**
> ℹ️ 
> ℹ️ Besides other usage issues, if you have a large number of environments (>500), it will impact the calculations that need to be done and the size of the Lucene index.
> ℹ️ 
> ℹ️ Please try to have a limited, restricted, and well-defined list of Test Environments.