public void Update()
 {
     if (suite.RunOneTest())
     {
         UUnitTestResult result = suite.GetResults();
         Debug.Log(result.Summary());
         GameObject.Destroy(gameObject);
     }
 }
Пример #2
0
        public static void TestImmediately()
        {
            ClearDebugLog();
            UUnitTestSuite suite = new UUnitTestSuite();

            suite.FindAndAddAllTestCases(typeof(UUnitTestCase));
            suite.RunAllTests();
            UUnitTestResult result = suite.GetResults();

            if (!result.AllTestsPassed())
            {
                Debug.LogWarning(result.Summary());
                throw new Exception("Not all tests passed.");
            }
            else
            {
                Debug.Log(result.Summary());
            }
        }
Пример #3
0
        public void Run(UUnitTestResult testResult)
        {
            UUnitTestResult.TestState testState = UUnitTestResult.TestState.FAILED;
            string message = null;

            eachTestStopwatch.Reset();
            setUpStopwatch.Reset();
            tearDownStopwatch.Reset();

            try
            {
                testResult.TestStarted();

                setUpStopwatch.Start();
                SetUp();
                setUpStopwatch.Stop();

                Type       type   = this.GetType();
                MethodInfo method = type.GetRuntimeMethod(testMethodName, EMPTY_PARAMETER_TYPES);                    // Test methods must contain no parameters
                UUnitAssert.NotNull(method, "Could not execute: " + testMethodName + ", it's probably not public."); // Limited access to loaded assemblies
                eachTestStopwatch.Start();
                ((UUnitTestDelegate)method.CreateDelegate(typeof(UUnitTestDelegate), this))();                       // This creates a delegate of the test function, and calls it
                testState = UUnitTestResult.TestState.PASSED;
            }
            catch (UUnitAssertException e)
            {
                message   = e.ToString();
                testState = UUnitTestResult.TestState.FAILED;
            }
            catch (UUnitSkipException)
            {
                // message remains null
                testState = UUnitTestResult.TestState.SKIPPED;
            }
            catch (TargetInvocationException e)
            {
                message   = e.InnerException.ToString();
                testState = UUnitTestResult.TestState.FAILED;
            }
            catch (Exception e)
            {
                message   = e.ToString();
                testState = UUnitTestResult.TestState.FAILED;
            }
            finally
            {
                eachTestStopwatch.Stop();

                if (testState != UUnitTestResult.TestState.SKIPPED)
                {
                    try
                    {
                        tearDownStopwatch.Start();
                        TearDown();
                        tearDownStopwatch.Stop();
                    }
                    catch (Exception e)
                    {
                        message   = e.ToString();
                        testState = UUnitTestResult.TestState.FAILED;
                    }
                }
            }

            testResult.TestComplete(testMethodName, testState, eachTestStopwatch.ElapsedMilliseconds, message);
        }
Пример #4
0
        public void Run(UUnitTestResult testResult)
        {
            UUnitTestResult.TestState testState = UUnitTestResult.TestState.FAILED;
            string message = null;
            eachTestStopwatch.Reset();
            setUpStopwatch.Reset();
            tearDownStopwatch.Reset();

            try
            {
                testResult.TestStarted();

                setUpStopwatch.Start();
                SetUp();
                setUpStopwatch.Stop();

                Type type = this.GetType();
                MethodInfo method = type.GetRuntimeMethod(testMethodName, EMPTY_PARAMETER_TYPES); // Test methods must contain no parameters
                UUnitAssert.NotNull(method, "Could not execute: " + testMethodName + ", it's probably not public."); // Limited access to loaded assemblies
                eachTestStopwatch.Start();
                ((UUnitTestDelegate)method.CreateDelegate(typeof(UUnitTestDelegate), this))(); // This creates a delegate of the test function, and calls it
                testState = UUnitTestResult.TestState.PASSED;
            }
            catch (UUnitAssertException e)
            {
                message = e.ToString();
                testState = UUnitTestResult.TestState.FAILED;
            }
            catch (UUnitSkipException)
            {
                // message remains null
                testState = UUnitTestResult.TestState.SKIPPED;
            }
            catch (TargetInvocationException e)
            {
                message = e.InnerException.ToString();
                testState = UUnitTestResult.TestState.FAILED;
            }
            catch (Exception e)
            {
                message = e.ToString();
                testState = UUnitTestResult.TestState.FAILED;
            }
            finally
            {
                eachTestStopwatch.Stop();

                if (testState != UUnitTestResult.TestState.SKIPPED)
                {
                    try
                    {
                        tearDownStopwatch.Start();
                        TearDown();
                        tearDownStopwatch.Stop();
                    }
                    catch (Exception e)
                    {
                        message = e.ToString();
                        testState = UUnitTestResult.TestState.FAILED;
                    }
                }
            }

            testResult.TestComplete(testMethodName, testState, eachTestStopwatch.ElapsedMilliseconds, message);
        }
Пример #5
0
        public void Run(UUnitTestResult testResult)
        {
            UUnitTestResult.TestState testState = UUnitTestResult.TestState.FAILED;
            string message = null;

            eachTestStopwatch.Reset();
            setUpStopwatch.Reset();
            tearDownStopwatch.Reset();

            try
            {
                testResult.TestStarted();

                setUpStopwatch.Start();
                SetUp();
                setUpStopwatch.Stop();

                Type       type   = this.GetType();
                MethodInfo method = type.GetMethod(testMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                UUnitAssert.NotNull(method, "Could not execute: " + testMethodName + ", it's probably not public."); // Limited access to loaded assemblies
                eachTestStopwatch.Start();
                method.Invoke(this, null);
                testState = UUnitTestResult.TestState.PASSED;
            }
            catch (UUnitSkipException)
            {
                // message remains null
                testState = UUnitTestResult.TestState.SKIPPED;
            }
            catch (UUnitAssertException e)
            {
                message   = e.ToString();
                testState = UUnitTestResult.TestState.FAILED;
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException is UUnitSkipException)
                {
                    // message remains null
                    testState = UUnitTestResult.TestState.SKIPPED;
                }
                else
                {
                    message   = e.InnerException.ToString();
                    testState = UUnitTestResult.TestState.FAILED;
                }
            }
            catch (Exception e)
            {
                message   = e.ToString();
                testState = UUnitTestResult.TestState.FAILED;
            }
            finally
            {
                eachTestStopwatch.Stop();

                if (testState != UUnitTestResult.TestState.SKIPPED)
                {
                    try
                    {
                        tearDownStopwatch.Start();
                        TearDown();
                        tearDownStopwatch.Stop();
                    }
                    catch (Exception e)
                    {
                        message   = e.ToString();
                        testState = UUnitTestResult.TestState.FAILED;
                    }
                }
            }

            testResult.TestComplete(testMethodName, testState, eachTestStopwatch.ElapsedMilliseconds, message);
        }
        public void Run(UUnitTestResult testResult)
        {
            UUnitTestResult.TestState testState = UUnitTestResult.TestState.FAILED;
            string message = null;
            eachTestStopwatch.Reset();
            setUpStopwatch.Reset();
            tearDownStopwatch.Reset();

            try
            {
                testResult.TestStarted();

                setUpStopwatch.Start();
                SetUp();
                setUpStopwatch.Stop();

                Type type = this.GetType();
                MethodInfo method = type.GetMethod(testMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                UUnitAssert.NotNull(method, "Could not execute: " + testMethodName + ", it's probably not public."); // Limited access to loaded assemblies
                eachTestStopwatch.Start();
                method.Invoke(this, null);
                testState = UUnitTestResult.TestState.PASSED;
            }
            catch (UUnitSkipException)
            {
                // message remains null
                testState = UUnitTestResult.TestState.SKIPPED;
            }
            catch (UUnitAssertException e)
            {
                message = e.ToString();
                testState = UUnitTestResult.TestState.FAILED;
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException is UUnitSkipException)
                {
                    // message remains null
                    testState = UUnitTestResult.TestState.SKIPPED;
                }
                else
                {
                    message = e.InnerException.ToString();
                    testState = UUnitTestResult.TestState.FAILED;
                }
            }
            catch (Exception e)
            {
                message = e.ToString();
                testState = UUnitTestResult.TestState.FAILED;
            }
            finally
            {
                eachTestStopwatch.Stop();

                if (testState != UUnitTestResult.TestState.SKIPPED)
                {
                    try
                    {
                        tearDownStopwatch.Start();
                        TearDown();
                        tearDownStopwatch.Stop();
                    }
                    catch (Exception e)
                    {
                        message = e.ToString();
                        testState = UUnitTestResult.TestState.FAILED;
                    }
                }
            }

            testResult.TestComplete(testMethodName, testState, eachTestStopwatch.ElapsedMilliseconds, message);
        }