< Summary

Class:GDX.Developer.Reports.BuildVerification.TestRunner
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Developer/Reports/BuildVerification/TestRunner.cs
Covered lines:0
Uncovered lines:57
Coverable lines:57
Total lines:102
Line coverage:0% (0 of 57)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:7
Method coverage:0% (0 of 7)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TestRunner()0%2100%
AddTest(...)0%6200%
EvaluateTestScene()0%20400%
EvaluateTestScene()0%1321100%
RemoveTest(...)0%2100%
Reset()0%2100%
HasRemainingTests()0%2100%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Developer/Reports/BuildVerification/TestRunner.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System.Diagnostics;
 6using System.Globalization;
 7using System.Threading.Tasks;
 8using GDX.Collections.Generic;
 9using UnityEngine.SceneManagement;
 10
 11namespace GDX.Developer.Reports.BuildVerification
 12{
 13    public static class TestRunner
 14    {
 015        static SimpleList<ITestBehaviour> s_KnownTest = new SimpleList<ITestBehaviour>(10);
 016        static Stopwatch s_Timer = new Stopwatch();
 17
 18        public static void AddTest(SimpleTestBehaviour simpleTest)
 019        {
 020            if (!s_KnownTest.ContainsReference(simpleTest))
 021            {
 022                s_KnownTest.AddWithExpandCheck(simpleTest);
 023            }
 024        }
 25
 26
 27        public static async Task EvaluateTestScene(string scenePath, float millisecondTimeout = 30000)
 028        {
 029            int sceneBuildIndex = SceneUtility.GetBuildIndexByScenePath(scenePath);
 030            if (sceneBuildIndex < 0)
 031            {
 032                Trace.Output(Trace.TraceLevel.Error, $"[BVT] Unable to find scene: {scenePath}");
 033                return;
 34            }
 035            await EvaluateTestScene(sceneBuildIndex, millisecondTimeout);
 036        }
 37
 38        public static async Task EvaluateTestScene(int sceneBuildIndex, float millisecondTimeout = 30000)
 039        {
 040            string scenePath = SceneUtility.GetScenePathByBuildIndex(sceneBuildIndex);
 41
 42            // Load the desired scene
 043            new Task(() =>
 044            {
 045                Trace.Output(Trace.TraceLevel.Info, $"[BVT] Load {scenePath}");
 046                SceneManager.LoadScene(sceneBuildIndex, LoadSceneMode.Additive);
 047            }).RunSynchronously();
 48
 49            // Generic settling delay
 050            await Task.Delay(100);
 51
 52            // Restart timer for timeout
 053            s_Timer.Restart();
 054            while (HasRemainingTests())
 055            {
 056                if (s_Timer.ElapsedMilliseconds < millisecondTimeout)
 057                {
 058                    await Task.Delay(100);
 059                }
 60                else
 061                {
 062                    Trace.Output(Trace.TraceLevel.Warning, $"[BVT] Test run timed out after {(s_Timer.ElapsedMillisecond
 063                    for (int i = 0; i < s_KnownTest.Count; i++)
 064                    {
 065                        BuildVerificationReport.Assert(s_KnownTest.Array[i].GetIdentifier(), false, "Test timed out.");
 066                    }
 067                    s_KnownTest.Clear();
 068                }
 069            }
 70
 71            // Make sure we remove all registered as a safety precaution / will also stop the timer
 072            Reset();
 73
 074            new Task(() => {
 075                Trace.Output(Trace.TraceLevel.Info, $"[BVT] Unload {scenePath}");
 076                SceneManager.UnloadSceneAsync(sceneBuildIndex);
 077            }).RunSynchronously();
 78
 079            await Task.Delay(250);
 080        }
 81
 82
 83        public static void RemoveTest(SimpleTestBehaviour simpleTest)
 084        {
 085            s_KnownTest.RemoveFirstItem(simpleTest);
 086        }
 87
 88
 89        public static void Reset()
 090        {
 091            s_KnownTest.Clear();
 092            s_Timer.Stop();
 093        }
 94
 95        static bool HasRemainingTests()
 096        {
 097            return s_KnownTest.Count > 0;
 098        }
 99
 100
 101    }
 102}