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."); }
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 }
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)); }
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 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 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)); }
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)); }