[Adapdev-commits] Adapdev/src/Adapdev.UnitTest.Core TestRunner.cs,1.5,1.6 TestSuite.cs,1.1.1.1,1.2 T
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-06-09 04:21:11
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11294/src/Adapdev.UnitTest.Core Modified Files: TestRunner.cs TestSuite.cs TestSummary.cs TextFormatter.cs Log Message: Index: TestSummary.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TestSummary.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TestSummary.cs 28 Feb 2005 01:32:23 -0000 1.1.1.1 --- TestSummary.cs 9 Jun 2005 04:20:23 -0000 1.2 *************** *** 74,77 **** --- 74,91 ---- get{return 1 - this.PercentPassed;} } + + public double TotalDuration + { + get + { + double duration = 0; + foreach(TestAssemblyResult t in this.tar) + { + duration += t.GetTotalDuration(); + } + return duration; + } + + } } } Index: TestRunner.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TestRunner.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TestRunner.cs 5 Jun 2005 08:50:32 -0000 1.5 --- TestRunner.cs 9 Jun 2005 04:20:23 -0000 1.6 *************** *** 44,47 **** --- 44,48 ---- using Adapdev.Diagnostics; using log4net; + using NUnit.Framework; public delegate double ThreadedTestHandler(MethodInfo method, object o); *************** *** 184,358 **** foreach (Test test in tf.GetTests()) { ! 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(); ! System.Console.SetOut(consoleWriter); ! System.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.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(Adapdev.UnitTest.IgnoreException) || e.InnerException.GetType() == typeof(NUnit.Framework.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)); - } --- 185,368 ---- 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 { } } Index: TestSuite.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TestSuite.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TestSuite.cs 28 Feb 2005 01:32:23 -0000 1.1.1.1 --- TestSuite.cs 9 Jun 2005 04:20:23 -0000 1.2 *************** *** 50,53 **** --- 50,54 ---- protected int passedTestCount = 0; protected int ignoredTestCount = 0; + protected double _duration = 0; public TestSuite(){} *************** *** 109,112 **** --- 110,114 ---- } } + } } \ No newline at end of file Index: TextFormatter.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TextFormatter.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TextFormatter.cs 24 Apr 2005 04:59:08 -0000 1.4 --- TextFormatter.cs 9 Jun 2005 04:20:23 -0000 1.5 *************** *** 65,74 **** sb.Append("SUMMARY\r\n"); sb.Append("========================================\r\n"); ! return String.Format("P\t\tF\t\tI\r\n{0}\t\t{1}\t\t{2}\r\n" + ! "Percent Passed: {3}\r\n", ts.TotalPassed, ts.TotalFailed, ts.TotalIgnored, ! ts.PercentPassed.ToString("P")); } --- 65,74 ---- sb.Append("SUMMARY\r\n"); sb.Append("========================================\r\n"); ! return String.Format("Passed: {0}\t\tFailed: {1}\t\tIgnored: {2}\r\nPercent Passed: {3}\t\r\nTime:{4}s\r\n", ts.TotalPassed, ts.TotalFailed, ts.TotalIgnored, ! ts.PercentPassed.ToString("P"), ! ts.TotalDuration); } *************** *** 86,90 **** { if(tar.Iterations.Count > 1) sb.Append(this.GetNesting(nesting) + "Iteration: " + ati.Iteration + "\r\n"); ! sb.AppendFormat(this.GetNesting(nesting + 1) + this.GetMarker(tar) + "{0} - {1}\r\n", tar.Name, tar.State); if((tar is TestResult) && ((tar as TestResult).Description.Length > 0)) sb.AppendFormat(this.GetNesting(nesting + 2) + "Description: {0}\r\n", (tar as TestResult).Description); --- 86,90 ---- { if(tar.Iterations.Count > 1) sb.Append(this.GetNesting(nesting) + "Iteration: " + ati.Iteration + "\r\n"); ! sb.AppendFormat(this.GetNesting(nesting + 1) + this.GetMarker(tar) + "{0} - {1}\t\t\tTime: {2}s\r\n", tar.Name, tar.State, tar.GetAverageDuration()); if((tar is TestResult) && ((tar as TestResult).Description.Length > 0)) sb.AppendFormat(this.GetNesting(nesting + 2) + "Description: {0}\r\n", (tar as TestResult).Description); |