Test Intelligence™ step
Use the Test step to leverage Test Intelligence.
Test Intelligence accelerates your test cycles without compromising quality, by running only the unit tests that are relevant to the code changes that triggered the build. Rather than running all test, all the time Instead of always running all unit tests, Harness automatically skips unneeded tests, speeding up your builds. You can also configure Harness TI to automatically split tests and run them in parallel.
You can use this Test Intelligence step, also known as the Test step, to run unit tests with Python, Ruby, Java , C# , Scala and Kotlin programming languages.
Configure the Test step
Add the Test step to the Build stage in a CI pipeline.
- step:
type: Test
name: Intelligent Tests
identifier: test
spec:
command: mvn test # Required. All other settings are optional.
shell: sh # Optional shell type.
connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR # Container registry connector.
image: repo/image # Container image to use to run the commands.
privileged: false
intelligenceMode: true # Enable Test Intelligence.
globs: # Test glob pattern.
- "some/glob/pattern"
reports: # Test report path.
- "**/*.xml"
envVariables:
MAVEN_OPTS: "-Djansi.force=true"Metadata
Name: Enter a name summarizing the step's purpose. Harness automatically assigns an ID based on the Name.
Description: Optional text string describing the step's purpose.
Container Registry and Image
The build environment must have the necessary binaries for the Test step to execute your test commands. Depending on the stage's build infrastructure, Test steps can use binaries that exist in the build environment, or use Container Registry and Image to pull an image, such as a public or private Docker image, that contains the required binaries.
Command and Shell
Use these fields to define the commands that you need to run in this step.
For Shell, select the shell type. If the step includes commands that aren't supported for the selected shell type, the step fails. Required binaries must be available on the build infrastructure or through a specified Container Registry and Image. The default shell type, if unspecified, is Sh.
In the Command field, enter commands for this step. The script is invoked as if it were the entry point. If the step runs in a container, the commands are executed inside the container.
Intelligence Mode
Enable Intelligence Mode to enable Test Intelligence.
Test Globs
Specify a glob pattern to match the test files you want to include.
By default, we use the following globs for test selection:
Ruby:
**/spec/**/*_spec.rbPython:
"**/test_*.py,**/*_test.py"Java:
**/*.javaC#:
**/*.cs
You can override the default test globs pattern, for example:
The default for RSpec is **/spec/**/*_spec.rb, and you could override it with any other pattern, such as spec/features/**/*_spec.rb, which would look for a /spec directory at the root level, rather than anywhere in the workspace.
Since test selection is at the file-level, the test globs pattern references file names. You can include directory structures, such as microservice1/**/test_*.py.
Report Paths
This setting is optional. If unspecified, Harness uses the default JUnit report path **/*.xml or **/*.trx for C#.
You can use this setting if your test reports are stored in a non-default location or have a non-default name pattern.
For example:
You can add multiple paths. If you specify multiple paths, make sure the files contain unique tests to avoid duplicates. Glob is supported. Go to Format test reports for supported formats.
Output Variables
Output variables expose values for use by other steps or stages in the pipeline.
Secrets in output variables exposed in logs: If an output variable value contains a secret, be aware that the secret will be visible in the build details. Such secrets are visible on the Output tab of the step where the output variable originates and in the build logs for any later steps that reference that variable. For information about best practices for using secrets in pipelines, go to the Secrets documentation.
64KB length limit: If an output variable's length is greater than 64KB, steps can fail or truncate the output. If you need to export large amounts of data, consider uploading artifacts or exporting artifacts by email.
Single line limit: By default, output variables are limited to a single line. To enable multi-line output variables, use the feature flag
CI_ENABLE_MULTILINE_OUTPUTS_SECRETS. To export multi-line data, you can also consider uploading artifacts or exporting artifacts by email.Exit Codes: In the event that an exit code is defined and set in the script, the output variables will not be available as an output from the step because it is a "forced" exit. The output from the step will be empty which can be desired depending on the situation. This includes
exit 0definitions. Therefore, customers should not define an exit 0 situation, as "completing the script" to the end is what is expected as a "healthy" completion of the script.
Create an output variable
To create an output variable, do the following in the step where the output variable originates:
In the Command field, export the output variable. For example, the following command exports a variable called
myVarwith a value ofvarValue:In the step's Output Variables, declare the variable name, such as
myVar.
Reference an output variable
To reference an output variable in a later step or stage in the same pipeline, use a variable expression that includes the originating step's ID and the variable's name.
Use either of the following expressions to reference an output variable in another step in the same stage:
To reference an output variable in a stage other than the one where the output variable originated, use either of the following expressions:

Environment Variables
You can inject environment variables into the step container and use them in the step's commands. You must input a Name and Value for each variable.
You can reference environment variables in the Command by name, such as $var_name.
Variable values can be fixed values, runtime inputs, or expressions. For example, if the value type is expression, you can input a value that references the value of some other setting in the stage or pipeline.

Parallelism (Test Splitting)
To enable parallelism (test splitting) in a Test step, specify the number of parallel workloads to divide the tests into. These workloades will be executed in parallel steps.
MATRIX LOOPING STRATEGY NOT SUPPORTED
The Test step does not support the matrix looping strategy. Using the Test step inside a matrix produces undefined behavior and is not a supported configuration.
If you need matrix looping to run different services or modules in parallel, use the Run step instead.
For example:
Additional container settings
Settings specific to containers are not applicable in a stages that use VM or Harness Cloud build infrastructure.
Image Pull Policy
If you specified a Container Registry and Image, you can specify an image pull policy:
Always: The kubelet queries the container image registry to resolve the name to an image digest every time the kubelet launches a container. If the kubelet encounters an exact digest cached locally, it uses its cached image; otherwise, the kubelet downloads (pulls) the image with the resolved digest, and uses that image to launch the container.
If Not Present: The image is pulled only if it isn't already present locally.
Never: The image is not pulled.
Run as User
If you specified a Container Registry and Image, you can specify the user ID to use for running processes in containerized steps.
For a Kubernetes cluster build infrastructure, the step uses this user ID to run all processes in the pod. For more information, go to Set the security context for a pod.
Privileged
For container-based build infrastructures, you can enable this option to run the container with escalated privileges. This is equivalent to running a container with the Docker --privileged flag.
Set Container Resources
These settings specify the maximum resources used by the container at runtime. These setting are only available for container-based build infrastructures, such as a Kubernetes cluster build infrastructure.
Limit Memory: The maximum memory that the container can use. You can express memory as a plain integer or as a fixed-point number using the suffixes
GorM. You can also use the power-of-two equivalentsGiandMi. The default is500Mi.Limit CPU: The maximum number of cores that the container can use. CPU limits are measured in CPU units. Fractional requests are allowed. For example, you can specify one hundred millicpu as
0.1or100m. The default is400m. For more information go to Resource units in Kubernetes.
Timeout
You can set the step's timeout limit. Once the timeout is reached, the step fails and pipeline execution proceeds according to any Step Failure Strategy settings or Step Skip Condition settings.
Compatibility
The following are the languages, OSes & versions that are supported by Harness' Test Intelligence:
Supported Operating Systems
All cloud available versions of Linux, Windows & Mac are supported.
Supported languages
Language
Minimum Version
Java
8+
Kotlin
1.5+
Scala
2.13+
Supported Build Tools
Build Tool
Minimum Version
Maximum Version
Comments
Gradle
7.x+
9.0.2
Maven
3.6.x+
3.9.x
Bazel
7.x+
8.x
Supported Operating Systems
All cloud available versions of Linux, Windows & Mac are supported.
Supported languages
Language
Minimum Version
Ruby
2.7+
Supported Test Frameworks
Test Framework
Minimum Version
Maximum Version
Comments
RSpec
7.x+
8.x
Supported Operating Systems
All cloud available versions of Linux, Windows & Mac are supported.
Supported languages
Language
Minimum Version
Python
3.8+
Supported Test Frameworks
Test Framework
Minimum Version
Maximum Version
Comments
Pytest
8.0+
9.0.2
Supports pytest-xdist 3.6.1+ and pytest-cov 7+
Supported Operating Systems
Operating System
Supported Versions
Architectures
Linux/Centos
8+
AMD64
Linux/RedHat
9+
AMD64 & ARM64
Linux/Debian
12+
AMD64 & ARM64
Linux/Suse
15.5+
AMD64 & ARM64
Linux/Ubuntu
20.04+
AMD64 & ARM64
Alpine
3.17+
AMD64 & ARM64
Windows
TBD
AMD64
Supported Implementations
Implementation
Minimum Version
.Net Core
6+
.Net Framework
TBD
Supported Operating Systems
All cloud available versions of Linux & Windows are supported.
Supported languages
Language
Minimum Version
Maximum Version
JavaScript
ES2017
ES2024
Typescript
v4.x+
v5.x
Supported Engine
Engine
Minimum Version
Maximum Version
Node.JS
v18.x+
v24.x
Supported Test Frameworks
Test Framework
Minimum Version
Maximum Version
Comments
Jest
26.x+
30.x
Trigger Test Selection
Test Intelligence (TI) uses a baseline call graph to determine which tests to run. The process to establish this baseline differs for branch runs and pull request (PR) runs.
For Branch Runs (Manual or Triggered by Push)
Branch runs do not require webhook triggers.
Required Steps:
Push changes to the branch, or manually run the pipeline from the UI.
Select Git Branch as the build type and enter the branch name.
Wait for the build to complete. This run establishes the baseline.
Push further changes to the same branch and rerun the pipeline.
TI will apply test selection based on code differences from the baseline.
For Pull Request (PR) Runs
For PR-based pipelines, webhook triggers are required to make TI function correctly. Specifically:
A trigger for the PR Opened event is needed to capture the initial call graph.
A trigger for the PR Closed (Merged) event is required so that the platform can finalize the baseline. The merge event does not need to start a pipeline execution; it just needs to emit the event.
Required Steps:
Create a webhook trigger that listens for:
Pull Request Opened
Pull Request Closed (Merged)
Open a PR against the target branch. The PR trigger should automatically start a pipeline run using Git Pull Request as the build type.
Merge the PR. The trigger listening for PR merge must fire. This event is used by Harness in the background to finalize the baseline for that branch. It does not need to execute any stage or pipeline.
Once the baseline is established, new PRs targeting the same base branch will apply test selection during their pipeline runs.
If a new PR is created against a different base branch, you must repeat steps 2 and 3 to establish a new baseline for that branch.
Why do I have to run the pipeline twice?
The first time you run a pipeline after adding the Run Test step, Harness creates a baseline for test selection in future builds. Test selection isn't applied to this run because Harness has no baseline against which to compare changes and select tests. You'll start seeing test selection and time savings on the second run after you have added the Test step.
Ignore tests or files
If you want Test Intelligence to ignore certain tests or files, create a .ticonfig.yaml file in your codebase, and list the tests and files to ignore. For example:
Troubleshoot Test Intelligence
Go to the CI Knowledge Base for more questions and issues related to Test Intelligence, including:
Last updated
Was this helpful?
