public void RunTestsOfJUUTTestClassWithFailingClassSetUp()
        {
            TestClassSession session = new TestClassSession(typeof(TestClassMockWithFailingClassSetUp));
            session.Add(typeof(TestClassMockWithFailingClassSetUp).GetMethod("Bar"));

            //Testing the run of a specific testMethod
            TestRunner runner = new SimpleTestRunner();
            ClassReport classReport = runner.Run(session);
            AssertThatTheMethodsAreCalledInTheCorrectOrderAfterRunningATestWithFailingClassSetUp();

            //Checking the returned test report
            Report report = GetFirstMethodReportFrom(classReport.MethodReports);
            Exception raisedException = new NullReferenceException("Failing class set up.");
            Report expectedReport = new MethodReport(typeof(TestClassMockWithFailingClassSetUp).GetMethod("ClassSetUp"), raisedException);
            AssertEx.That(report, Is.EqualTo(expectedReport));

            //Testing the run of all tests
            MethodCallOrder = new List<string>();
            session.AddAll();
            classReport = runner.Run(session);
            AssertThatTheMethodsAreCalledInTheCorrectOrderAfterRunningATestWithFailingClassSetUp();

            //Checking the returned test reports
            ICollection<MethodReport> reports = classReport.MethodReports;
            raisedException = new NullReferenceException("Failing class set up.");
            expectedReport = new MethodReport(typeof(TestClassMockWithFailingClassSetUp).GetMethod("ClassSetUp"), raisedException);
            AssertEx.That(reports.Count, Is.EqualTo(1));
            AssertEx.That(GetFirstMethodReportFrom(reports), Is.EqualTo(expectedReport));
        }
Example #2
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;
        }
Example #3
0
        public void EqualsAndHashCode()
        {
            TestClassSession session = new TestClassSession(typeof(TestClassMock));
            session.AddAll();

            //Using IsTrue/IsFalse to cover all paths (aren't covered, when using Equals)
            //Equal tests
            Assert.IsTrue(session.Equals(session), "An object should allways be equal to itself (reference).");
            AssertEx.That(session.GetHashCode(), Is.EqualTo(session.GetHashCode()), "Equal objects should have equal hashcodes.");

            TestClassSession equal = new TestClassSession(typeof(TestClassMock));
            equal.AddAll();
            Assert.IsTrue(session.Equals(equal), "An object should be equal to an object with the same attributes.");
            AssertEx.That(session.GetHashCode(), Is.EqualTo(equal.GetHashCode()), "Equal objects should have equal hashcodes.");

            //Not equal tests
            Assert.IsFalse(session.Equals(null), "An object shouldn't be equal to null.");

            object unequal = new object();
            Assert.IsFalse(session.Equals(unequal), "An object shouldn't be equal to an object of an other type.");
            AssertEx.That(session.GetHashCode(), Is.Not(unequal.GetHashCode()), "Unequal objects shouldn't have equal hashcodes.");

            unequal = new TestClassSession(typeof(AnotherTestClassMock));
            Assert.IsFalse(session.Equals(unequal), "An object shouldn't be equal to an object with different attributes.");
            AssertEx.That(session.GetHashCode(), Is.Not(unequal.GetHashCode()), "Unequal objects shouldn't have equal hashcodes.");

            unequal = new TestClassSession(typeof(TestClassMock));
            ((TestClassSession) unequal).Add(typeof(TestClassMock).GetMethod("FirstTestMethod"));
            Assert.IsFalse(session.Equals(unequal), "An object shouldn't be equal to an object with different attributes.");
            AssertEx.That(session.GetHashCode(), Is.Not(unequal.GetHashCode()), "Unequal objects shouldn't have equal hashcodes.");
        }
Example #4
0
        public void Creation()
        {
            TestClassSession runner = new TestClassSession(typeof(TestClassMock));
            AssertEx.That(runner.TestClass, Is.EqualTo(typeof(TestClassMock)));

            AssertEx.That(() => new SimpleClassReport(null), Throws.An<ArgumentException>());
            AssertEx.That(() => new SimpleClassReport(typeof(NotAttributedMock)), Throws.An<ArgumentException>());
        }
        public void RunTestAfterMethodCall()
        {
            TestClassSession session = new TestClassSession(typeof(TestClassMock));
            session.AddAll();

            TestRunner runner = new CollectingTestRunner();
            AssertEx.That(runner.Run(session), Is.Null());

            //TODO Other runner is needed
        }
Example #6
0
        public void MethodManagement()
        {
            TestClassSession classSession = new TestClassSession(typeof(TestClassMock));

            classSession.Add(typeof(TestClassMock).GetMethod("FirstTestMethod"));
            HashSet<MethodInfo> expectedMethods = new HashSet<MethodInfo> { typeof(TestClassMock).GetMethod("FirstTestMethod") };
            Assert.IsTrue(expectedMethods.SetEquals(classSession.TestsToRun));

            classSession.AddAll();
            expectedMethods.Add(typeof(TestClassMock).GetMethod("SecondTestMethod"));
            Assert.IsTrue(expectedMethods.SetEquals(classSession.TestsToRun));
        }
Example #7
0
        public void CreateSessionForAssembly()
        {
            Assembly assembly = Assembly.GetAssembly(typeof(AssemblyTestMock1));

            HashSet<TestClassSession> expectedClassSessions = new HashSet<TestClassSession>();
            TestClassSession classSession = new TestClassSession(typeof(AssemblyTestMock1));
            classSession.AddAll();
            expectedClassSessions.Add(classSession);
            classSession = new TestClassSession(typeof(AssemblyTestMock2));
            classSession.AddAll();
            expectedClassSessions.Add(classSession);

            AssertEx.That(expectedClassSessions.SetEquals(AssemblyScanner.CreateSessionFor(assembly).TestClassSessions), Is.True());
        }
        public void RunSpecificTestOfJUUTTestClass()
        {
            TestClassSession session = new TestClassSession(typeof(TestClassMock));
            session.Add(typeof(TestClassMock).GetMethod("Foo"));

            TestRunner runner = new SimpleTestRunner();
            ClassReport classReport = runner.Run(session);
            AssertThatTheMethodsAreCalledInTheCorrectOrderAfterRunningASpecificTest();

            //Checking the returned test report
            Report report = GetFirstMethodReportFrom(classReport.MethodReports);
            Report expectedReport = new MethodReport(typeof(TestClassMock).GetMethod("Foo"));
            AssertEx.That(report, Is.EqualTo(expectedReport));
        }
        public void RunAllTestsOfJUUTTestClass()
        {
            TestClassSession session = new TestClassSession(typeof(TestClassMock));
            session.AddAll();

            TestRunner runner = new SimpleTestRunner();
            ClassReport classReport = runner.Run(session);
            AssertThatTheMethodsAreCalledInTheCorrectOrderAfterRunningAllTests();

            //Checking the created test reports
            ICollection<MethodReport> resultReports = classReport.MethodReports;
            AssertEx.That(resultReports.Count, Is.EqualTo(2));
            foreach (MethodReport report in resultReports) {
                AssertThatTheReportIsEqualToFooOrBar(report);
            }
        }
        public void RunTestsOfJUUTTestClassWithFailingTestMethod()
        {
            TestClassSession session = new TestClassSession(typeof(TestClassMockWithFailingTestMethod));
            session.AddAll();

            TestRunner runner = new SimpleTestRunner();
            ClassReport classReport = runner.Run(session);
            AssertThatTheMethodsAreCalledInTheCorrectOrderAfterRunningATestWithFailingTestMethod();

            //Checking the returned test reports
            ICollection<MethodReport> reports = classReport.MethodReports;

            ICollection<MethodReport> expectedReports = new HashSet<MethodReport>();
            expectedReports.Add(new MethodReport(typeof(TestClassMockWithFailingTestMethod).GetMethod("FailingTest"),
                new NullReferenceException("Failing test method.")));
            expectedReports.Add(new MethodReport(typeof(TestClassMockWithFailingTestMethod).GetMethod("WorkingTest")));

            AssertEx.That(reports.Count, Is.EqualTo(2));
            Assert.IsTrue(expectedReports.SequenceEqual(reports));
        }
Example #11
0
 private bool Equals(TestClassSession other)
 {
     return TestClass.Equals(other.TestClass) && TestsToRun.SetEquals(other.TestsToRun);
 }
Example #12
0
 public ClassReport Run(TestClassSession session)
 {
     throw new System.NotImplementedException();
 }
Example #13
0
 public void MethodAdding()
 {
     TestClassSession session = new TestClassSession(typeof(ThirdTestClassMock));
     AssertEx.That(() => session.Add(typeof(AnotherTestClassMock).GetMethod("TestMethod")), Throws.An<ArgumentException>());
     AssertEx.That(() => session.Add(typeof(ThirdTestClassMock).GetMethod("NotAttributedMethod")), Throws.An<ArgumentException>());
 }