public void Run(ITomTest test) { string name = test.TestName; string expected = test.ExpectedOutput; TestStarted(name); try { TomSkipAttribute attr = test.GetType().GetCustomAttribute <TomSkipAttribute> (); if (attr != null) { TestSkipped(attr.Reason); } else { int startTime = Environment.TickCount; TextWriter oldWriter = Console.Out; StringWriter newOut = new StringWriter(); Console.SetOut(newOut); try { test.Run(); } finally { Console.SetOut(oldWriter); } int endTime = Environment.TickCount; TestCompleted(expected, newOut.ToString(), endTime - startTime); } } catch (Exception e) { TestFailed(e); } _writer.Flush(); }
public void RunAll(IEnumerable <Assembly> assemblies) { _testCount = _passCount = _failCount = _skipCount = 0; List <Type> allTestTypes = TestClasses(assemblies).OrderBy(t => t.Name).ToList(); _writer.WriteStartElement("tests"); foreach (Type t in allTestTypes) { // can't be null - see IsATestClass ConstructorInfo ci = t.GetConstructor(new Type [0]); ITomTest test = (ITomTest)ci.Invoke(null); Run(test); } _writer.WriteEndElement(); AppendText($"Executed {_testCount}. {_passCount} passed, {_failCount} failed, {_skipCount} skipped.\n"); TestsDone(this, new EventArgs()); }