Run a test and check the results
After you run a test for the first time to create a reference image, run the test again when you want to check for changes.
Note: To run a test with a C# script instead, refer to the GraphicsTestBuildManager and GraphicsTestBuilder API documentation.
Run the test
To run the test, follow these steps:
- From the main menu, select Window > General > Test Runner to open the Test Runner window.
- Select your test.
- Select Run Selected.
Unity generates the following in the Project window:
- The captured image from the test run. The file name ends in
Test. - The reference image the test used as a comparison, if the test fails. The file name ends in
.expected - An image with the difference between the two images, if the test fails. The file name ends in
.diff.
Unity also generates an XML test report called TestResults.xml in the user folder of your computer.
For more information, refer to Run tests in the Test Runner window.
Note: If you run a test in Edit Mode or Play Mode, Unity uses assets directly from the Project window. If you run a Player test, Unity adds assets to an AssetBundle for runtime code to load.
Compare the images
To compare the images, follow these steps:
- From the main menu, select Window > General > Graphics Tests to open the Graphics Tests window.
- Select your test.
- Select the correct tab. For example, if Unity saved the captured image in
Assets/ActualImages/Linear/WindowsEditor/Direct3D12/None, select the linear-windowseditor-direct3d12-none tab. - Move the slider to compare the captured image with the reference image.
For more information, refer to Graphics Tests window reference.
Check why the test failed
Check the reasons why a test failed.
To make tests less sensitive to differences in the images, refer to Change the comparison settings.
Check in your C# script
To get the result of the test, add an ImageComparisonResults out parameter when you call the ImageAssert API. For example:
ImageAssert.AreEqual(
testCase.ReferenceImage.Image,
actualTexture,
settings,
expectedImagePathLog: testCase.ReferenceImage.LoadMessage,
saveFailedImage: true,
saveFailedImageToDisk: false,
logMessages: true,
result: out ImageComparisonResults result
);
Check the logs
The Graphics Test Framework adds logs in the following places:
- The Logs tab in the Graphics Tests window.
- The Console window.
- A
GraphicsTestLogs.logfile in theLogsfolder.
To add your own logs, use the GraphicsTestLogger API. For example:
GraphicsTestLogger.Log("Camera clear flags: " + camera.clearFlags);
GraphicsTestLogger.Log("Render pipeline: " + GraphicsSettings.currentRenderPipeline?.name);