Exemple #1
0
        /// <summary>
        /// Runs all tests and returns the reports of the runned tests.
        /// </summary>
        /// <param name="session"></param>
        public ClassReport Run(TestClassSession session)
        {
            Type testClass = session.TestClass;
            ClassReport report = new SimpleClassReport(testClass);

            MethodReport methodReport = RunClassSetUp(testClass);
            if (methodReport != null) {
                report.Add(methodReport);
                return report;
            }

            object testInstance = Activator.CreateInstance(testClass);
            foreach (MethodInfo test in session.TestsToRun) {
                methodReport = RunTestSetUp(testInstance, testClass);
                if (methodReport != null) {
                    report.Add(methodReport);
                    return report;
                }

                report.Add(RunTest(testInstance, test));

                methodReport = RunTestTearDown(testInstance, testClass);
                if (methodReport != null) {
                    report.Add(methodReport);
                    return report;
                }
            }

            methodReport = RunClassTearDown(testClass);
            if (methodReport != null) {
                report.Add(methodReport);
            }
            return report;
        }
Exemple #2
0
        public void AddingMethodReport()
        {
            Type type = typeof(TestClass);
            MethodInfo succeededMethod = type.GetMethod("TestName");
            MethodInfo failedMethod = type.GetMethod("SecondTest");
            ClassReport report = new SimpleClassReport(type);

            MethodReport methodReport1 = new MethodReport(succeededMethod);
            report.Add(methodReport1);
            AssertEx.That(report.Status is ReportStatus.Success, Is.True());
            AssertEx.That(report.SucceededTests, Is.EqualTo(1));
            AssertEx.That(report.RunnedTests, Is.EqualTo(1));

            MethodReport methodReport2 = new MethodReport(failedMethod, new AssertException("Exception Text"));
            report.Add(methodReport2);
            AssertEx.That(report.Status is ReportStatus.Failed, Is.True());
            AssertEx.That(report.FailedTests, Is.EqualTo(1));
            AssertEx.That(report.RunnedTests, Is.EqualTo(2));

            //This tests, that new reports of the same method will be replaced
            MethodReport methodReport3 = new MethodReport(succeededMethod, new NullReferenceException());
            report.Add(methodReport3);
            AssertEx.That(report.Status is ReportStatus.Error, Is.True());
            AssertEx.That(report.FailedTests, Is.EqualTo(2));
            AssertEx.That(report.RunnedTests, Is.EqualTo(2));

            //Reports for methods of another class aren't allowed
            MethodInfo methodInfo = typeof(AnotherTestClass).GetMethod("AnotherTest");
            MethodReport reportOfMethodNotInClass = new MethodReport(methodInfo);
            AssertEx.That(() => report.Add(reportOfMethodNotInClass), Throws.An<ArgumentException>());
        }
Exemple #3
0
        public void TextCreation()
        {
            Type type = typeof(TestClass);
            MethodInfo succeededMethod = type.GetMethod("TestName");
            MethodInfo failedMethod = type.GetMethod("SecondTest");
            ClassReport report = new SimpleClassReport(type);

            AssertEx.That(report.Text, Is.EqualTo("No tests have been runned."));

            MethodReport methodReport1 = new MethodReport(succeededMethod);
            report.Add(methodReport1);
            AssertEx.That(report.Text, Is.EqualTo("1 test runned: 0 failed, 1 succeeded"));

            MethodReport methodReport2 = new MethodReport(failedMethod, new AssertException("Exception Text"));
            report.Add(methodReport2);
            AssertEx.That(report.Text, Is.EqualTo("2 tests runned: 1 failed, 1 succeeded\n" +
                                                  "\n" +
                                                  "The SecondTest-Method failed."));

            MethodReport methodReport3 = new MethodReport(succeededMethod, new NullReferenceException());
            report.Add(methodReport3);
            AssertEx.That(report.Text, Is.EqualTo("2 tests runned: 2 failed, 0 succeeded\n" +
                                                  "\n" +
                                                  "The TestName-Method threw an unexpected exception.\n" +
                                                  "\n" +
                                                  "The SecondTest-Method failed."));
        }