您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

57 行
1.7 KiB

using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.TestTools.Graphics;
using UnityEngine.SceneManagement;
using UnityEngine.Events;
public class HDRP_GraphicTestRunner
{
[UnityTest, Category("HDRP Graphic Tests")]
[PrebuildSetup("SetupGraphicsTestCases")]
[UseGraphicsTestCases]
public IEnumerator Run(GraphicsTestCase testCase)
{
SceneManager.LoadScene(testCase.ScenePath);
// Arbitrary wait for 5 frames for the scene to load, and other stuff to happen (like Realtime GI to appear ...)
for (int i=0 ; i<5 ; ++i)
yield return null;
// Load the test settings
var settings = GameObject.FindObjectOfType<HDRP_TestSettings>();
var camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
if (camera == null) camera = GameObject.FindObjectOfType<Camera>();
if (camera == null)
{
Assert.Fail("Missing camera for graphic tests.");
}
Time.captureFramerate = settings.captureFramerate;
if (settings.doBeforeTest != null)
{
settings.doBeforeTest.Invoke();
// Wait again one frame, to be sure.
yield return null;
}
for (int i=0 ; i<settings.waitFrames ; ++i)
yield return null;
ImageAssert.AreEqual(testCase.ReferenceImage, camera, (settings != null)?settings.ImageComparisonSettings:null);
}
#if UNITY_EDITOR
[TearDown]
public void DumpImagesInEditor()
{
UnityEditor.TestTools.Graphics.ResultsUtility.ExtractImagesFromTestProperties(TestContext.CurrentContext.Test);
}
#endif
}