| | 1 | | using System; |
| | 2 | | using System.Diagnostics; |
| | 3 | | using GDX.Developer.Reports.NUnit; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace GDX.Developer.Reports.BuildVerification |
| | 7 | | { |
| | 8 | | public abstract class SimpleTestBehaviour : MonoBehaviour, ITestBehaviour |
| | 9 | | { |
| 0 | 10 | | int m_frameWait = 5; |
| | 11 | | string m_StartTime; |
| | 12 | | Stopwatch m_Timer; |
| | 13 | |
|
| | 14 | | void Start() |
| 0 | 15 | | { |
| 0 | 16 | | TestRunner.AddTest(this); |
| 0 | 17 | | } |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Run the test in Unity's late update |
| | 21 | | /// </summary> |
| | 22 | | #pragma warning disable IDE0051 |
| | 23 | | // ReSharper disable UnusedMember.Local |
| | 24 | | void Update() |
| 0 | 25 | | { |
| | 26 | | // Handle frame delay |
| 0 | 27 | | if (m_frameWait > 0) |
| 0 | 28 | | { |
| 0 | 29 | | m_frameWait--; |
| 0 | 30 | | return; |
| | 31 | | } |
| | 32 | |
|
| 0 | 33 | | if (m_frameWait < 0) |
| 0 | 34 | | { |
| 0 | 35 | | return; |
| | 36 | | } |
| | 37 | |
|
| 0 | 38 | | m_frameWait--; |
| | 39 | |
|
| 0 | 40 | | m_StartTime = DateTime.Now.ToString(Localization.UtcTimestampFormat); |
| 0 | 41 | | m_Timer = new Stopwatch(); |
| 0 | 42 | | m_Timer.Restart(); |
| | 43 | |
|
| 0 | 44 | | TestCase testCase = RunTest(); |
| | 45 | |
|
| 0 | 46 | | m_Timer.Stop(); |
| 0 | 47 | | testCase.Duration = m_Timer.ElapsedMilliseconds / 1000f; |
| 0 | 48 | | testCase.EndTime = DateTime.Now.ToString(Localization.UtcTimestampFormat); |
| 0 | 49 | | testCase.StartTime = m_StartTime; |
| | 50 | |
|
| 0 | 51 | | TestRunner.RemoveTest(this); |
| 0 | 52 | | } |
| | 53 | |
|
| | 54 | | // ReSharper restore UnusedMember.Local |
| | 55 | | #pragma warning restore IDE0051 |
| | 56 | |
|
| | 57 | | public abstract TestCase Check(); |
| | 58 | | public abstract string GetIdentifier(); |
| | 59 | |
|
| | 60 | | /// <inheritdoc /> |
| | 61 | | public virtual void Setup() |
| 0 | 62 | | { |
| 0 | 63 | | } |
| | 64 | |
|
| | 65 | | /// <inheritdoc /> |
| | 66 | | public virtual void TearDown() |
| 0 | 67 | | { |
| 0 | 68 | | } |
| | 69 | |
|
| | 70 | | TestCase RunTest() |
| 0 | 71 | | { |
| | 72 | | try |
| 0 | 73 | | { |
| 0 | 74 | | Setup(); |
| 0 | 75 | | TestCase testCase = Check(); |
| 0 | 76 | | TearDown(); |
| 0 | 77 | | return testCase; |
| | 78 | | } |
| 0 | 79 | | catch (Exception e) |
| 0 | 80 | | { |
| 0 | 81 | | TestCase testCase = BuildVerificationReport.Assert(GetIdentifier(), false, e.Message); |
| 0 | 82 | | testCase.StackTrace = e.StackTrace; |
| 0 | 83 | | TearDown(); |
| 0 | 84 | | return testCase; |
| | 85 | | } |
| 0 | 86 | | } |
| | 87 | | } |
| | 88 | | } |