public void RunTestCommand_Will_Execute_Passing_Test()
        {
            TestMethodViewModel viewModel = new TestMethodViewModel(AddResultControl, ClearResultControl);

            MockTestManager testManager = new MockTestManager();
            testManager.PassTests = true;

            viewModel.TestManager = testManager;

            TestFixture fixture = new TestFixture();

            TestMethod testMethod = new TestMethod();
            testMethod.Name = "test1";
            fixture.Tests = new List<TestMethod>();
            fixture.Tests.Add(testMethod);

            viewModel.Tests = new List<TestFixture>();
            viewModel.Tests.Add(fixture);

            viewModel.RunTestsCommand.Execute(null);

            Thread.Sleep(5000);

            Confirm.Equal(1, viewModel.TestsPassed);
            Confirm.Equal(0,viewModel.TestsFailed);
        }
예제 #2
0
        public TestResult RunTest(TestMethod method)
        {
            TestResult res = new TestResult();
            res.Passed = PassTests;

            return res;
        }
예제 #3
0
 protected void SetTreeNodeColor(TestMethod node, string color)
 {
     Dispatcher.Invoke(DispatcherPriority.Normal,
          new Action(
              delegate()
              {
                  node.Color = color;
              }
              ));
 }
예제 #4
0
        public void TestManager_RunTest_Will_Run_Failing_Test_When_Confirm_Different_Fails_Test()
        {
            TestManager manager = new TestManager();
            TestMethod method = new TestMethod();
            method.Name = "FailingStubWithFailingConfirmDifferent";
            method.Type = typeof(TestManagerTest);

            Type t = typeof(TestManagerTest);
            var q = from m in t.GetMembers()
                    where m.Name == "FailingStubWithFailingConfirmDifferent"
                    select m;

            method.MemberInfo = q.Single<MemberInfo>();

            TestResult res = manager.RunTest(method);
            Confirm.Equal("The the actual value should not be equal to Not Expected Value", res.ResultText);
            Confirm.Equal(false, res.Passed);
        }
예제 #5
0
        public void TestManager_RunTest_Will_Run_Failing_Test_When_Confirm_Equals_Fails_Test()
        {
            TestManager manager = new TestManager();
            TestMethod method = new TestMethod();
            method.Name = "FailingStubWithFailingConfirmEquals";
            method.Type = typeof(TestManagerTest);

            Type t = typeof(TestManagerTest);
            var q = from m in t.GetMembers()
                    where m.Name == "FailingStubWithFailingConfirmEquals"
                    select m;

            method.MemberInfo = q.Single<MemberInfo>();

            TestResult res = manager.RunTest(method);
            Confirm.Equal("The expected value is: [1], but the actual value is: [2]", res.ResultText);
            Confirm.Equal(false, res.Passed);
        }
예제 #6
0
        public void TestManager_RunTest_Will_Run_Passing_Test_Test()
        {
            TestManager manager = new TestManager();
            TestMethod method = new TestMethod();
            method.Name = "PassingStub";
            method.Type = typeof(TestManagerTest);
            method.MemberInfo = PassingStub();

            TestResult res = manager.RunTest(method);
            Confirm.Equal(true, res.Passed);
            Confirm.Equal("PassingStub (PASSED)", res.ResultText);
        }
예제 #7
0
        public void TestManager_RunTest_Will_Run_Failing_Test_When_Unhandled_Exception_Is_Thrown_Test()
        {
            TestManager manager = new TestManager();
            TestMethod method = new TestMethod();
            method.Name = "FailingStubWithUnhandledException";
            method.Type = typeof(TestManagerTest);

            Type t = typeof(TestManagerTest);
            var q = from m in t.GetMembers()
                    where m.Name == "FailingStubWithUnhandledException"
                    select m;

            method.MemberInfo = q.Single<MemberInfo>();

            TestResult res = manager.RunTest(method);
            Confirm.Equal(false, res.Passed);
            Confirm.Equal("Argument Invalid", res.ResultText);
        }
예제 #8
0
        public void TestManager_RunTest_Will_Run_Failing_Test_When_Confirm_IsGreater_Fails_Test()
        {
            TestManager manager = new TestManager();
            TestMethod method = new TestMethod();
            method.Name = "FailingStubWithFailingConfirmIsGreater";
            method.Type = typeof(TestManagerTest);

            Type t = typeof(TestManagerTest);
            var q = from m in t.GetMembers()
                    where m.Name == "FailingStubWithFailingConfirmIsGreater"
                    select m;

            method.MemberInfo = q.Single<MemberInfo>();

            TestResult res = manager.RunTest(method);
            Confirm.Equal("2.3 is not greater than 4.2", res.ResultText);
            Confirm.Equal(false, res.Passed);
        }
예제 #9
0
        public TestResult RunTest(TestMethod testMethod)
        {
            TestResult result;
            Stopwatch testTime = null;
            string fixture = null;
            try
            {
                var instance = Activator.CreateInstance(testMethod.Type);
                fixture = instance.GetType().Name;
                if (testMethod.TestSetup != null)
                {
                    testMethod.Type.InvokeMember(testMethod.TestSetup.Name, BindingFlags.InvokeMethod, null, instance, null);
                }

                testTime = Stopwatch.StartNew();
                testMethod.Type.InvokeMember(testMethod.Name, BindingFlags.InvokeMethod, null, instance, null);
                testTime.Stop();
                result = EnsureCorrectTestResult(testMethod.MemberInfo);
                result.Duration = testTime.Elapsed;

                if (testMethod.TestTearDown != null)
                {
                    testMethod.Type.InvokeMember(testMethod.TestTearDown.Name, BindingFlags.InvokeMethod, null, instance, null);
                }
            }
            catch (System.Exception ex)
            {
                TimeSpan testDuration = TimeSpan.Zero;
                if (testTime != null)
                {
                    testTime.Stop();
                    testDuration = testTime.Elapsed;
                }
                result = HandleFailedTest(testMethod.MemberInfo, testDuration, ex);
            }

            result.Fixture = fixture;
            result.TestName = testMethod.Name;
            result.UseCase = testMethod.UseCase;
            return result;
        }
예제 #10
0
        private void Run(TestMethod method)
        {
            method.Color = "Orange";

            TestResult res = TestManager.RunTest(method);

            AddTestResult(res,method);
        }
예제 #11
0
        private void AddTestResult(TestResult res, TestMethod method)
        {
            lock (testResultLock)
            {
                if (res.Passed == true)
                {
                    method.Color = "Green";
                    TestsPassed++;
                }
                else
                {
                    method.Color = "Red";
                    TestsFailed++;
                }

                this.addResultControl(res);
                this.TestResults.Add(res);

                xmlReportSaved = false;

                string summaryLine = String.Format("{0} / {1} Tests Run - {2} Succeeded - {3} Failed", TestsPassed + TestsFailed, TotalTestCount, TestsPassed, TestsFailed);
                string resultString = res.ToString();

                int lineSize = Math.Max(summaryLine.Length, resultString.Length);

                StringBuilder resultOutput = new StringBuilder();
                resultOutput.AppendLine(String.Empty.PadRight(lineSize, '*'));
                resultOutput.AppendLine(summaryLine);
                resultOutput.AppendLine(resultString);
                resultOutput.AppendLine(String.Empty.PadRight(lineSize, '*'));

                if (testsFailed > 0)
                {
                    resultOutput.AppendLine("Failed tests:");
                    var failedTests = testResults.Where(t => t.Passed == false);
                    foreach(var test in failedTests)
                    {
                        resultOutput.AppendLine(test.ToString());
                    }
                    resultOutput.AppendLine(String.Empty.PadRight(lineSize, '*'));
                }

                Console.WriteLine(resultOutput.ToString());
            }
        }
예제 #12
0
        private void EnsureCorrectTestResult(TestMethod method)
        {
            Confirm.IsTrue(method.TestSetup.Name == "TestSetup");

            Confirm.IsTrue(method.TestTearDown.Name == "TestTearDown");

            Confirm.Equal(typeof(MethodManagerTest), method.Type);
            Confirm.Equal("Yellow", method.Color);
        }