Runtime::Test
- Last UpdatedOct 07, 2026
- 2 minute read
The Runtime::Test class provides a function for code coverage and image comparison.
Code example
This is a code example for Runtime::Test.
Json coverage = Runtime::Test.GetCodeCoverageInfo();
Runtime::Environment.Print(coverage.ToString());
Compare images function
This function compares two images and returns true when they are visually similar within the configured tolerances; otherwise, returns false.
Required JSON fields: image1, image2, totalErrorTolerance (0–100), colorShiftTolerance.
-
image1and image2 could be either file paths or internal texture references with internal prefix.
For more information on how to reference internal texture, see Referencing Texture2D internal texture in the XR Nodes Guide.
-
Optional: clip1 and clip2 (x, y, width, height) to compare only sub-regions.
-
Optional: diffImage to output a diff image for mismatched pixels.
-
Optional: diffPixelColor (RGBA Vector4 string) to set highlight color in difference output (default: 255,166,0,255).
Code example
A code example for comparing images.
{
"expectedImage": {
"name": "C:/Tests/Baseline/MainScreen.png"
},
"runtimeImage": {
"name": " internal:BaselineTexture "
},
"totalErrorTolerance": 2.5,
"colorShiftTolerance": 5
}
OR
{
"expectedImage": {
"name": "internal:BaselineTexture",
"clip": {"x": 100, "y": 60, "width": 400, "height": 220}
},
"runtimeImage": {
"name": " C:/Tests/Baseline/MainScreen.png ",
"clip": {"x": 100, "y": 60, "width": 400, "height": 220}
},
"totalErrorTolerance": 1.0,
"colorShiftTolerance": 3,
"diffImage": "C:/Tests/Diff/MainScreen_Diff.png",
"diffPixelColor": "255,0,0,255"
}
Commands
The following table shows the commands currently accessible as static methods from Runtime::Test class.
|
Method |
Return type |
Parameters |
Description |
|---|---|---|---|
|
GetCodeCoverageInfo |
Json |
Returns a Json containing code coverage information, such as line hit, branch rate, and complexity for each method and class in your project.
To enable the code coverage, add an item app.debug.xrsCodeCoverage with type sbool and value true to your config file. |
|
|
CompareImages |
bool |
Jason |
Compares two images and returns true when they are visually similar within the configured tolerances; otherwise returns false. Required JSON fields: image1, image2, totalErrorTolerance (0–100), colorShiftTolerance
|