From ca992c34fd51d715e26845b95c8f75f53372b2f9 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Thu, 2 May 2024 21:55:14 +0900 Subject: [PATCH] Fix screenshot default filename when called out of test context --- RuntimeInternals/ScreenshotHelper.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/RuntimeInternals/ScreenshotHelper.cs b/RuntimeInternals/ScreenshotHelper.cs index 2c47322..e6a2459 100644 --- a/RuntimeInternals/ScreenshotHelper.cs +++ b/RuntimeInternals/ScreenshotHelper.cs @@ -22,15 +22,17 @@ public static class ScreenshotHelper private static string DefaultFilename(string callerMemberName) { #if UNITY_INCLUDE_TESTS - return TestContext.CurrentTestExecutionContext.CurrentTest.Name - .Replace('(', '_') - .Replace(')', '_') - .Replace(',', '-') - .Replace("\"", ""); - // Note: Same as the file name created under ActualImages of the Graphics Tests Framework package. -#else - return callerMemberName; + if (TestContext.CurrentTestExecutionContext != null) + { + return TestContext.CurrentTestExecutionContext.CurrentTest.Name + .Replace('(', '_') + .Replace(')', '_') + .Replace(',', '-') + .Replace("\"", ""); + // Note: Same as the file name created under ActualImages of the Graphics Tests Framework package. + } #endif + return callerMemberName; } ///