Beispiel #1
0
        //Overloads
        public override void        Fail(string message, string details)
        {
            //Handle the assert, treat it as an error.
            Exception e = new TestException(TestResult.Assert, message, details, null, null);

            e.Source = "Debug.Assert";

            //Note: We don't throw the exception (by default), since we want to continue on Asserts
            //(as many of them are benign or simply a valid runtime error).
            if (this.ShouldThrow)
            {
                throw e;
            }

            StackTrace stack = new StackTrace();

            TestLog.Error(TestResult.Assert, details, null, "Debug.Assert", message, stack.ToString(), null, 0);
        }
Beispiel #2
0
        public TestModule(string name, string desc)
            : base(name, desc, TestType.TestModule)
        {
            this.Guid = GetType().ToString();

            //Population
            //DetermineChildren();

            try
            {
                DetermineIncludes();
                DetermineFilters();
            }
            catch (Exception e)
            {
                //Don't completely block construction, otherwise it won't be able to be loaded from COM
                TestLog.HandleException(e);
            }
        }
Beispiel #3
0
        public static bool Warning(object actual, object expected, string message, Exception inner)
        {
            //See if these are equal
            bool equal = InternalEquals(actual, expected);

            if (equal)
            {
                return(true);
            }

            try
            {
                throw new TestWarningException(message, actual, expected, inner);
            }
            catch (Exception e)
            {
                //Warning should continue - not halt test progress
                TestLog.HandleException(e);
                return(false);
            }
        }
Beispiel #4
0
        public ITestItem                        CreateTest(String assembly, String type)
        {
            try
            {
//              this.Log        = new LtmContext() as ITestLog;
//              this.Properties = new LtmContext() as ITestProperties;

                //Create an instance
                //Note: Assembly.CreateInstance returns null for type not found
                TestModule test = (TestModule)Assembly.LoadFrom(assembly).CreateInstance(type);
                if (test == null)
                {
                    throw new TypeLoadException(
                              String.Format("Unable to find type: '{0}' in assembly: '{1}'", type, assembly)
                              );
                }
                return(test);
            }
            catch (Exception e)
            {
                TestLog.HandleException(e);
                throw new TestFailedException(e.Message, null, null, e);
            }
        }
Beispiel #5
0
 public override void Write(string text)
 {
     //Delegate
     TestLog.Write(pflags, text);
 }
Beispiel #6
0
 protected virtual TestResult HandleException(Exception e)
 {
     //Note: override this if your product has specilized exceptions (ie: nesting or collections)
     //that you need to recurse over of print out differently
     return(TestLog.HandleException(e));
 }
Beispiel #7
0
        TestResult ITestItem.Terminate()
        {
            //Enter
            OnEnter(TestMethod.Terminate);
            TestResult result = TestResult.Passed;

            //NOTE: Since exceptions are a way-of-life in C#, and the fact that they are just
            //caught by the runtime before passed back to LTM, we lose the entire stack and just
            //an unknown error code is returned.

            //To help solve this we will wrap the call in a try catch and actually
            //log the exception to the LTM output window...
            try
            {
                //Skipped
                if (this.Skipped || !this.Implemented)
                {
                    result = TestResult.Skipped;
                }
                else
                {
                    this.Terminate();
                }

                //Before exiting make sure we reset our CurChild to null, to prevent incorrect uses
                if (Parent != null)
                {
                    Parent.CurrentChild = null;
                }
            }
            catch (Exception e)
            {
                HandleException(e);
            }

            try
            {
                //Clear any previous existing info (in the static class).
                if (_testtype == TestType.TestModule)
                {
                    //Note: We actually have to clear these "statics" since they are not cleaned up
                    //until the process exits.  Which means that if you run again, in an apartment model
                    //thread it will try to release these when setting them which is not allowed to
                    //call a method on an object created in another apartment
                    TestInput.Dispose();
                    TestLog.Dispose();
                }
            }
            catch (Exception e)
            {
                result = HandleException(e);
            }

            //This is also a good point to hint to the GC to free up any unused memory
            //at the end of each TestCase and the end of each module.
            GC.Collect();
            GC.WaitForPendingFinalizers();

            //Leave
            OnLeave(TestMethod.Terminate);
            return(result);
        }
Beispiel #8
0
        public static TestResult            HandleException(Exception e)
        {
            TestResult result = TestResult.Failed;
            Exception  inner  = e;

            //If reflection was used check for test skipped/passed exception
            while (inner is TargetInvocationException)
            {
                inner = inner.InnerException;
            }

            if (!(inner is TestException) ||
                ((inner as TestException).Result != TestResult.Skipped &&
                 (inner as TestException).Result != TestResult.Passed &&
                 (inner as TestException).Result != TestResult.Warning))
            {
                inner = e; //start over so we do not loose the stack trace
            }
            while (inner != null)
            {
                //Need to handle Loader exceptions seperatly
                if (inner is ReflectionTypeLoadException)
                {
                    //Recurse
                    foreach (Exception loaderexception in ((ReflectionTypeLoadException)inner).LoaderExceptions)
                    {
                        HandleException(loaderexception);
                    }
                }

                //Source
                String source = inner.Source;

                //Message
                String message = inner.Message;
                if (inner != e)
                {
                    message = "Inner Exception -> " + message;
                }

                //Expected / Actual
                Object actual   = inner.GetType();
                Object expected = null;
                String details  = inner.StackTrace;
                String filename = null;
                int    line     = 0;
                if (inner is TestException)
                {
                    TestException testinner = (TestException)inner;

                    //Setup more meaningful info
                    actual   = testinner.Actual;
                    expected = testinner.Expected;
                    result   = testinner.Result;
                    switch (result)
                    {
                    case TestResult.Passed:
                    case TestResult.Skipped:
                        WriteLine(message);
                        return(result);                                 //were done
                    }
                    ;
                }

                //Log
                TestLog.Error(result, actual, expected, source, message, details, filename, line);

                //Next
                inner = inner.InnerException;
            }

            return(result);
        }