[Adapdev-commits] Adapdev/src/Adapdev.UnitTest.Core TestRunner.cs,1.6,1.7
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-06-12 14:24:39
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32060/src/Adapdev.UnitTest.Core Modified Files: TestRunner.cs Log Message: Index: TestRunner.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TestRunner.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TestRunner.cs 9 Jun 2005 04:20:23 -0000 1.6 --- TestRunner.cs 12 Jun 2005 14:24:29 -0000 1.7 *************** *** 163,377 **** { TestFixtureResult testFixtureResult = new TestFixtureResult(tf); - testFixtureResult.TestId = tf.Id; - string assembly = (tf.Parent.OriginalPath); - string classname = tf.Namespace + "." + tf.Class; - object o = new object(); - Assembly a = AssemblyCache.Get(tf.Parent.OriginalPath); - - if(this._debugMode) log.Debug("Running TF " + tf.Name); ! if(_dispatcher != null)_dispatcher.OnTestFixtureStarted(new TestFixtureEventArgs(tf)); ! for (int j = 1; j <= tf.RepeatCount; j++) { ! if (tf.RepeatDelay > 0) Thread.Sleep(tf.RepeatDelay); ! TestFixtureIteration tfi = new TestFixtureIteration(); ! if(_dispatcher != null)this._dispatcher.OnTestFixtureIterationStarted(new TestFixtureEventArgs(tf)); ! ! o = a.CreateInstance(classname); ! Type type = a.GetType(classname, true); ! this.RunTestFixtureSetUps(tf, o, type); ! foreach (Test test in tf.GetTests()) { ! try ! { ! MethodInfo m = type.GetMethod(test.Method); ! TestResult tr = new TestResult(test); ! tr.TestId = test.Id; ! tr.Description = test.Description; ! if(this._debugMode) log.Debug("Running T " + test.Name); ! if (!test.Ignore && test.ShouldRun) { ! if(_dispatcher != null)_dispatcher.OnTestStarted(new TestEventArgs(test)); ! for (int i = 1; i <= test.RepeatCount; i++) ! { ! TextWriter consoleOut = Console.Out; ! TextWriter errorOut = Console.Error; ! StringWriter consoleWriter = new StringWriter(); ! StringWriter errorWriter = new StringWriter(); ! StringWriter debugWriter = new StringWriter(); ! StringWriter traceWriter = new StringWriter(); ! Console.SetOut(consoleWriter); ! Console.SetError(errorWriter); ! TextWriterTraceListener debug = new TextWriterTraceListener(debugWriter); ! TextWriterTraceListener error = new TextWriterTraceListener(traceWriter); ! Debug.Listeners.Add(debug); ! Trace.Listeners.Add(error); ! if (test.RepeatDelay > 0) ! { ! Thread.Sleep(test.RepeatDelay); ! Console.WriteLine("Sleeping..." + test.RepeatDelay); ! } ! TestIteration ti = new TestIteration(); ! ti.Iteration = i; ! ti.Thread = AppDomain.GetCurrentThreadId().ToString(); ! long kStart = 0; ! long kEnd = 0; ! if(_dispatcher != null)this._dispatcher.OnTestIterationStarted(new TestEventArgs(test)); - try - { - this.RunTestSetUps(tf, test.Name, o, type); - kStart = Process.GetCurrentProcess().WorkingSet; - timer.Start(); - m.Invoke(o, null); - timer.Stop(); - ti.Duration = timer.Duration; - kEnd = Process.GetCurrentProcess().WorkingSet; - ti.MemoryUsed = (kEnd - kStart)/1024; ! if (test.MaxKMemory > 0 && test.MaxKMemory < ti.MemoryUsed) ! { ! ti.State = TestState.Fail; ! ti.Result = "Memory usage exceeded MaxK limit of " + test.MaxKMemory; ! } ! else if (test.MinOperationsPerSecond > 0 && ti.GetOpsPerSecond() < test.MinOperationsPerSecond) ! { ! ti.State = TestState.Fail; ! ti.Result = "Ops per second was less than minimum limit of " + test.MinOperationsPerSecond; ! } ! else if (test.ExpectedExceptionType != null && test.ExpectedExceptionType.Length > 0) { ! ti.State = TestState.Fail; ! ti.Result = "ExceptedException type " + test.ExpectedExceptionType + " was not thrown."; } ! else { ! ti.State = TestState.Pass; ! } ! this.RunTestTearDowns(tf, test.Name, o, type); ! } ! catch (Exception e) ! { ! timer.Stop(); ! ti.Duration = timer.Duration; ! kEnd = Process.GetCurrentProcess().WorkingSet; ! if (test.ExpectedExceptionType != null && test.ExpectedExceptionType.Length > 0) { ! Type t = null; ! foreach(Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) { ! try { ! t = ass.GetType(test.ExpectedExceptionType, true, true); ! break; } - catch(Exception){} - } ! if(t == null) throw new TypeLoadException("Unable to locate " + test.ExpectedExceptionType + ". Please make sure it is correct."); ! if (e.InnerException.GetType().IsSubclassOf(t) || e.InnerException.GetType() == t) ! { ! if(test.ExpectedExceptionMessage != null && test.ExpectedExceptionMessage.Length > 0) { ! if(test.ExpectedExceptionMessage.ToLower() == e.InnerException.Message.ToLower()) { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was thrown. Message: " + e.InnerException.Message; ! ti.State = TestState.Pass; } else { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was thrown, but wrong message. Message: " + e.InnerException.Message + " - Expected: " + test.ExpectedExceptionMessage; ! ti.State = TestState.Fail; } } else { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was thrown. Message: " + e.InnerException.Message; ! ti.State = TestState.Pass; } } else { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was NOT thrown. Message: " + e.InnerException.Message; ti.State = TestState.Fail; } ! ti.ExceptionType = e.InnerException.GetType().FullName; ! ti.FullStackTrace = e.InnerException.StackTrace; ! ti.MemoryUsed = (kEnd - kStart)/1024; ! ! } ! // TODO : Fix incrementing of tests in GUI when IgnoreException is thrown ! else if(e.InnerException.GetType() == typeof(IgnoreException) || e.InnerException.GetType() == typeof(IgnoreException)) ! { ! ti.Result = e.InnerException.Message; ! ti.State = TestState.ForcedIgnore; ! ti.ExceptionType = e.InnerException.GetType().FullName; ! ti.FullStackTrace = e.InnerException.StackTrace; ! } ! else ! { ! ti.Result = e.InnerException.Message; ! ti.ExceptionType = e.InnerException.GetType().FullName; ! ti.FullStackTrace = e.InnerException.StackTrace; ! ti.State = TestState.Fail; } - this.RunTestTearDowns(tf, test.Name, o, type); - } ! ti.ConsoleOutput = consoleWriter.ToString(); ! ti.ConsoleError = errorWriter.ToString(); ! ti.DebugOutput = debugWriter.ToString(); ! ti.TraceOutput = traceWriter.ToString(); ! tr.AddIteration(ti); ! if(_dispatcher != null)_dispatcher.OnTestIterationCompleted(new TestIterationEventArgs(ti)); ! Console.SetOut(consoleOut); ! Console.SetError(errorOut); ! Debug.Listeners.Remove(debug); ! Trace.Listeners.Remove(error); ! debug.Dispose(); ! error.Dispose(); } } ! else { - TestIteration ti = new TestIteration(); - ti.State = TestState.Ignore; - ti.Result = test.IgnoreReason; - tr.AddIteration(ti); } - - if (tf.ShouldShow) tfi.AddTestResult(tr); - if(_dispatcher != null)_dispatcher.OnTestCompleted(new TestResultEventArgs(tr)); - } - catch (Exception e) - { - Console.WriteLine(e.Message + " " + e.StackTrace); - } - finally - { } - } ! this.RunTestFixtureTearDowns(tf, o, type); ! tfi.Iteration = j; ! testFixtureResult.AddIteration(tfi); ! if(_dispatcher != null)_dispatcher.OnTestFixtureIterationCompleted(new TestFixtureIterationEventArgs(tfi)); } - if(_dispatcher != null)_dispatcher.OnTestFixtureCompleted(new TestFixtureResultEventArgs(testFixtureResult)); - return testFixtureResult; } --- 163,384 ---- { TestFixtureResult testFixtureResult = new TestFixtureResult(tf); ! try { ! testFixtureResult.TestId = tf.Id; ! string assembly = (tf.Parent.OriginalPath); ! string classname = tf.Namespace + "." + tf.Class; ! object o = new object(); ! Assembly a = AssemblyCache.Get(tf.Parent.OriginalPath); ! if(this._debugMode) log.Debug("Running TF " + tf.Name); ! if(_dispatcher != null)_dispatcher.OnTestFixtureStarted(new TestFixtureEventArgs(tf)); ! for (int j = 1; j <= tf.RepeatCount; j++) { ! if (tf.RepeatDelay > 0) Thread.Sleep(tf.RepeatDelay); ! TestFixtureIteration tfi = new TestFixtureIteration(); ! if(_dispatcher != null)this._dispatcher.OnTestFixtureIterationStarted(new TestFixtureEventArgs(tf)); ! o = a.CreateInstance(classname); ! Type type = a.GetType(classname, true); ! this.RunTestFixtureSetUps(tf, o, type); ! ! foreach (Test test in tf.GetTests()) ! { ! try { + MethodInfo m = type.GetMethod(test.Method); + TestResult tr = new TestResult(test); + tr.TestId = test.Id; + tr.Description = test.Description; ! if(this._debugMode) log.Debug("Running T " + test.Name); ! if (!test.Ignore && test.ShouldRun) ! { ! if(_dispatcher != null)_dispatcher.OnTestStarted(new TestEventArgs(test)); ! for (int i = 1; i <= test.RepeatCount; i++) ! { + TextWriter consoleOut = Console.Out; + TextWriter errorOut = Console.Error; + StringWriter consoleWriter = new StringWriter(); + StringWriter errorWriter = new StringWriter(); + StringWriter debugWriter = new StringWriter(); + StringWriter traceWriter = new StringWriter(); ! Console.SetOut(consoleWriter); ! Console.SetError(errorWriter); ! TextWriterTraceListener debug = new TextWriterTraceListener(debugWriter); ! TextWriterTraceListener error = new TextWriterTraceListener(traceWriter); ! Debug.Listeners.Add(debug); ! Trace.Listeners.Add(error); ! if (test.RepeatDelay > 0) { ! Thread.Sleep(test.RepeatDelay); ! Console.WriteLine("Sleeping..." + test.RepeatDelay); } ! TestIteration ti = new TestIteration(); ! ti.Iteration = i; ! ti.Thread = AppDomain.GetCurrentThreadId().ToString(); ! long kStart = 0; ! long kEnd = 0; ! if(_dispatcher != null)this._dispatcher.OnTestIterationStarted(new TestEventArgs(test)); ! ! try { ! this.RunTestSetUps(tf, test.Name, o, type); ! kStart = Process.GetCurrentProcess().WorkingSet; ! timer.Start(); ! m.Invoke(o, null); ! timer.Stop(); ! ti.Duration = timer.Duration; ! kEnd = Process.GetCurrentProcess().WorkingSet; ! ti.MemoryUsed = (kEnd - kStart)/1024; ! if (test.MaxKMemory > 0 && test.MaxKMemory < ti.MemoryUsed) ! { ! ti.State = TestState.Fail; ! ti.Result = "Memory usage exceeded MaxK limit of " + test.MaxKMemory; ! } ! else if (test.MinOperationsPerSecond > 0 && ti.GetOpsPerSecond() < test.MinOperationsPerSecond) ! { ! ti.State = TestState.Fail; ! ti.Result = "Ops per second was less than minimum limit of " + test.MinOperationsPerSecond; ! } ! else if (test.ExpectedExceptionType != null && test.ExpectedExceptionType.Length > 0) ! { ! ti.State = TestState.Fail; ! ti.Result = "ExceptedException type " + test.ExpectedExceptionType + " was not thrown."; ! } ! else ! { ! ti.State = TestState.Pass; ! } ! ! this.RunTestTearDowns(tf, test.Name, o, type); ! } ! catch (Exception e) { ! timer.Stop(); ! ti.Duration = timer.Duration; ! kEnd = Process.GetCurrentProcess().WorkingSet; ! if (test.ExpectedExceptionType != null && test.ExpectedExceptionType.Length > 0) { ! Type t = null; ! foreach(Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) { ! try ! { ! t = ass.GetType(test.ExpectedExceptionType, true, true); ! break; ! } ! catch(Exception){} } ! if(t == null) throw new TypeLoadException("Unable to locate " + test.ExpectedExceptionType + ". Please make sure it is correct."); ! if (e.InnerException.GetType().IsSubclassOf(t) || e.InnerException.GetType() == t) { ! if(test.ExpectedExceptionMessage != null && test.ExpectedExceptionMessage.Length > 0) { ! if(test.ExpectedExceptionMessage.ToLower() == e.InnerException.Message.ToLower()) ! { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was thrown. Message: " + e.InnerException.Message; ! ti.State = TestState.Pass; ! } ! else ! { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was thrown, but wrong message. Message: " + e.InnerException.Message + " - Expected: " + test.ExpectedExceptionMessage; ! ti.State = TestState.Fail; ! } } else { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was thrown. Message: " + e.InnerException.Message; ! ti.State = TestState.Pass; } } else { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was NOT thrown. Message: " + e.InnerException.Message; ! ti.State = TestState.Fail; } + ti.ExceptionType = e.InnerException.GetType().FullName; + ti.FullStackTrace = e.InnerException.StackTrace; + ti.MemoryUsed = (kEnd - kStart)/1024; + + } + // TODO : Fix incrementing of tests in GUI when IgnoreException is thrown + else if(e.InnerException.GetType() == typeof(IgnoreException) || e.InnerException.GetType() == typeof(IgnoreException)) + { + ti.Result = e.InnerException.Message; + ti.State = TestState.ForcedIgnore; + ti.ExceptionType = e.InnerException.GetType().FullName; + ti.FullStackTrace = e.InnerException.StackTrace; } else { ! ti.Result = e.InnerException.Message; ! ti.ExceptionType = e.InnerException.GetType().FullName; ! ti.FullStackTrace = e.InnerException.StackTrace; ti.State = TestState.Fail; } ! this.RunTestTearDowns(tf, test.Name, o, type); } ! ti.ConsoleOutput = consoleWriter.ToString(); ! ti.ConsoleError = errorWriter.ToString(); ! ti.DebugOutput = debugWriter.ToString(); ! ti.TraceOutput = traceWriter.ToString(); ! tr.AddIteration(ti); ! if(_dispatcher != null)_dispatcher.OnTestIterationCompleted(new TestIterationEventArgs(ti)); ! Console.SetOut(consoleOut); ! Console.SetError(errorOut); ! Debug.Listeners.Remove(debug); ! Trace.Listeners.Remove(error); ! debug.Dispose(); ! error.Dispose(); ! } ! ! } ! else ! { ! TestIteration ti = new TestIteration(); ! ti.State = TestState.Ignore; ! ti.Result = test.IgnoreReason; ! tr.AddIteration(ti); } + if (tf.ShouldShow) tfi.AddTestResult(tr); + if(_dispatcher != null)_dispatcher.OnTestCompleted(new TestResultEventArgs(tr)); } ! catch (Exception e) ! { ! Console.WriteLine(e.Message + " " + e.StackTrace); ! } ! finally { } } ! this.RunTestFixtureTearDowns(tf, o, type); ! tfi.Iteration = j; ! testFixtureResult.AddIteration(tfi); ! if(_dispatcher != null)_dispatcher.OnTestFixtureIterationCompleted(new TestFixtureIterationEventArgs(tfi)); ! } ! if(_dispatcher != null)_dispatcher.OnTestFixtureCompleted(new TestFixtureResultEventArgs(testFixtureResult)); ! } ! catch (Exception e) ! { ! Console.Write(e); } return testFixtureResult; } *************** *** 394,400 **** foreach (BaseTestHelper t in tf.GetFixtureSetUps()) { ! if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); ! MethodInfo m = type.GetMethod(t.Method); ! m.Invoke(instance, null); } } --- 401,414 ---- foreach (BaseTestHelper t in tf.GetFixtureSetUps()) { ! try ! { ! if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); ! MethodInfo m = type.GetMethod(t.Method); ! m.Invoke(instance, null); ! } ! catch (Exception e) ! { ! Console.Write(e); ! } } } *************** *** 404,410 **** foreach (BaseTestHelper t in tf.GetFixtureTearDowns()) { ! if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); ! MethodInfo m = type.GetMethod(t.Method); ! m.Invoke(instance, null); } } --- 418,431 ---- foreach (BaseTestHelper t in tf.GetFixtureTearDowns()) { ! try ! { ! if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); ! MethodInfo m = type.GetMethod(t.Method); ! m.Invoke(instance, null); ! } ! catch (Exception e) ! { ! Console.Write(e); ! } } } *************** *** 414,423 **** foreach (TestHelper t in tf.GetTestSetUps()) { ! // Console.WriteLine(t.Method); ! if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) { ! if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); ! MethodInfo m = type.GetMethod(t.Method); ! m.Invoke(instance, null); } } --- 435,451 ---- foreach (TestHelper t in tf.GetTestSetUps()) { ! try { ! // Console.WriteLine(t.Method); ! if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) ! { ! if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); ! MethodInfo m = type.GetMethod(t.Method); ! m.Invoke(instance, null); ! } ! } ! catch (Exception e) ! { ! Console.Write(e); } } *************** *** 428,436 **** foreach (TestHelper t in tf.GetTestTearDowns()) { ! if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) { ! if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); ! MethodInfo m = type.GetMethod(t.Method); ! m.Invoke(instance, null); } } --- 456,471 ---- foreach (TestHelper t in tf.GetTestTearDowns()) { ! try { ! if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) ! { ! if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); ! MethodInfo m = type.GetMethod(t.Method); ! m.Invoke(instance, null); ! } ! } ! catch (Exception e) ! { ! Console.Write(e); } } |