コード例 #1
0
        protected internal static ITestRunner <TTestMethod> GetTestRunner <TTestMethod>(Assembly assembly, ILogger logger) where TTestMethod : TestMethod
        {
            ITestRunner <TTestMethod> runner = TestRunner <TTestMethod> .Create(assembly, logger);

            if (Arguments != null && Arguments.Contains("tag"))
            {
                runner.Tag = Arguments["tag"];
            }
            runner.NoTestsDiscovered += (o, e) => OutLineFormat("No tests were found in {0}", ConsoleColor.Yellow, assembly.FullName);
            runner.TestsDiscovered   += (o, e) =>
            {
                TestsDiscoveredEventArgs <TTestMethod> args = (TestsDiscoveredEventArgs <TTestMethod>)e;
                OutLineFormat("Running all tests in {0}", ConsoleColor.Green, args.Assembly.FullName);
                OutLineFormat("\tFound {0} tests", ConsoleColor.Cyan, args.Tests.Count);
            };
            runner.TestPassed += (o, e) =>
            {
                TestEventArgs <TTestMethod> args = (TestEventArgs <TTestMethod>)e;
                Pass(args.Test.Information);
            };
            runner.TestFailed += (o, t) =>
            {
                TestExceptionEventArgs args = (TestExceptionEventArgs)t;
                Out("Test Failed: " + args.TestMethod.Information + "\r\n", ConsoleColor.Red);
                Out(args.Exception.Message, ConsoleColor.Magenta);
                Out();
                Out(args.Exception.StackTrace, ConsoleColor.Red);
                Out("---", ConsoleColor.Red);
                Out();
            };
            runner.TestsFinished += (o, e) =>
            {
                TestEventArgs <TTestMethod> args    = (TestEventArgs <TTestMethod>)e;
                TestRunnerSummary           summary = args.TestRunner.TestSummary;
                Out();
                OutLine("********");
                if (summary.FailedTests.Count > 0)
                {
                    OutLineFormat("({0}) tests passed", ConsoleColor.Green, summary.PassedTests.Count);
                    OutLineFormat("({0}) tests failed", ConsoleColor.Red, summary.FailedTests.Count);
                    summary.FailedTests.ForEach(cim =>
                    {
                        Out("\t");
                        MethodInfo method     = cim.Test.Method;
                        Type type             = method.DeclaringType;
                        string testIdentifier = $"{type.Namespace}.{type.Name}.{method.Name}";
                        OutLineFormat("{0}: ({1})", new ConsoleColorCombo(ConsoleColor.Yellow, ConsoleColor.Red), cim.Test.Information, testIdentifier);
                    });
                }
                else
                {
                    OutLineFormat("All ({0}) tests passed", ConsoleColor.Green, summary.PassedTests.Count);
                }
                OutLine("********");
            };
            return(runner);
        }
コード例 #2
0
ファイル: TestRunListener.cs プロジェクト: dekkerb115/Bam.Net
 public abstract void TestFailed(object sender, TestExceptionEventArgs args);
コード例 #3
0
 public override void TestFailed(object sender, TestExceptionEventArgs args)
 {
     FailedTests.Add(new UnitTestFailure(args));
     base.TestFailed(sender, args);
     TestFailedAction?.Invoke(args);
 }