Graphics test workflow
Follow this workflow to write a test that compares a texture or a capture of your scene to a reference image, and fails if the images are different.
Follow these steps:
- Create a test assembly file.
- Write a test that captures an image of the scene or a texture you render into, then compares it against a reference image.
- Run the test for the first time to create a reference image for future tests.
- Run the test and check the results.
Note: If you haven't yet created a graphics test, you can create and try two simple example tests from the Graphics Tests window. For more information, refer to Get started.
Create a test assembly
Create a test assembly .asmdef file in your project, and include the following assemblies in the references section:
UnityEngine.TestTools.GraphicsUnityEditor.TestTools.Graphics
For more information, refer to Create a test assembly.
To create an example assembly file in your project, refer to Get started.
Write a test
Write a test to do any of the following:
- Write a scene test. Load a scene and capture a camera view, then test it against a reference image.
- Write a rendering code test. Render into a texture, then test it against a reference image.
- Write a Unity Editor window test. Capture a Unity Editor window, then test it against a reference image.
- Write a shader test. Test a ShaderLab shader or an HLSL method.
Run the test for the first time
To run the test for the first time, follow these steps:
Use the Test Runner window to run the test.
The first time you run a test, it fails because there's no reference image to check the capture against yet.
Use the Graphics Tests window to check the reference image represents the correct output, then make it the reference image for future tests.
For more information, refer to Run a test for the first time.
Run the test and check the results
Run the test again using the Test Runner window, then check the test results in the Graphics Tests window. If the test image and the reference image are the same, the test passes.
For more information, refer to Run a test and check the results.