public TestCaseResult Execute()
        {
            string currentUser = Thread.CurrentThread.Name;

            FireExecutionBeginEvent(this, new TestCaseBeginExecutionArgs(currentUser));

            TestCaseResult testCaseResult = new TestCaseResult();

            testCaseResult.SetReferenceID(SystemID);
            testCaseResult.SetVirtualUser(currentUser);

            // Save copy of test property collection for restoration later (maintains scope)
            TestPropertyCollection savedTestPropertyCollection = new TestPropertyCollection(Core.TestProperties.TestPropertyCollection);

            AddRuntimeTestPropertiesToTestProperties();

            _testClassDictionary = new Dictionary <int, TestClassBase>();

            List <TestScriptObject> activeTestSteps = getActiveChildren();

            testCaseResult.SetStartTime(DateTime.Now);

            if (activeTestSteps.Count > 0)
            {
                // Iterate through each test step.
                foreach (TestStep testStep in activeTestSteps)
                {
                    // Only execute active test steps.
                    if (testStep.Status == Core.Status.Active)
                    {
                        // Stop if test case already failed (i.e., a previous test step has failed...UNLESS
                        // a) the test case is marked to continue on failure (continue regardless of previous failures.
                        // b) a specific test step is marked to always execute (regardless of previous failures).
                        if ((testCaseResult.TestVerdict != TestVerdict.Fail || OnTestStepFailure == OnFailure.Continue) || testStep.AlwaysExecute)
                        {
                            var producerResult = getProducerStepResult(testStep, testCaseResult);
                            var testStepResult = testStep.Execute(_testClassDictionary);

                            testCaseResult.AddResult(testStepResult);
                            testCaseResult.IncrementCounter(testStepResult.TestVerdict);

                            if (testStepResult.TestVerdict != TestVerdict.Pass)
                            {
                                testCaseResult.FinalizeVerdict();
                            }
                        }
                        else
                        {
                            var testStepResult = new TestStepResult(TestVerdict.DidNotExecute,
                                                                    "Did not execute as a previous step failed the test case." +
                                                                    "  To always run, consider setting the \"Always Run\" property to true.");
                            testCaseResult.AddResult(testStepResult);
                            testCaseResult.IncrementCounter(testStepResult.TestVerdict);
                            testStep.FireExecutionCompleteEvent(testStep, testStepResult);
                        }
                    }
                }
            }
            else
            {
                testCaseResult.SetTestVerdict(TestVerdict.DidNotExecute);
                testCaseResult.SetTestMessage("The test case is set to \"Active\", however it does not contain active test steps.");
            }

            testCaseResult.SetEndTime(DateTime.Now);
            testCaseResult.FinalizeVerdict();

            // Restore preserved test property collection.
            Core.TestProperties.SetTestPropertyCollection(savedTestPropertyCollection);

            FireExecutionCompleteEvent(this, testCaseResult);

            return(testCaseResult);
        }
Beispiel #2
0
        public TestCaseResult Execute()
        {
            string currentUser = Thread.CurrentThread.Name;

            FireExecutionBeginEvent(this, new TestCaseBeginExecutionArgs(currentUser));

            CheckForPossibleBreakpointMode();

            TestCaseResult testCaseResult = new TestCaseResult();

            testCaseResult.SetReferenceID(SystemID);
            testCaseResult.SetVirtualUser(currentUser);

            // Save copy of test property collection for restoration later (maintains scope)
            TestPropertyCollection savedTestPropertyCollection = new TestPropertyCollection(Core.TestProperties.TestPropertyCollection);

            AddRuntimeTestPropertiesToTestProperties();

            _testClassDictionary = new Dictionary <int, TestClassBase>();

            List <TestScriptObject> activeTestSteps = getActiveChildren();

            testCaseResult.SetStartTime(DateTime.Now);

            if (activeTestSteps.Count > 0)
            {
                // Iterate through each test step.
                foreach (TestStep testStep in activeTestSteps)
                {
                    var explanation = string.Empty;

                    // Determine is test steup should be run.  If so, execute.
                    if (determineExecutionStatus(testStep, testCaseResult, out explanation))
                    {
                        var testStepResult = testStep.Execute(_testClassDictionary);

                        testCaseResult.AddResult(testStepResult);
                        testCaseResult.IncrementCounter(testStepResult.TestVerdict);

                        if (testStepResult.TestVerdict != TestVerdict.Pass)
                        {
                            testCaseResult.FinalizeVerdict();
                        }
                    }
                    else
                    {
                        var testStepResult = new TestStepResult(TestVerdict.DidNotExecute, explanation);
                        testCaseResult.AddResult(testStepResult);
                        testCaseResult.IncrementCounter(testStepResult.TestVerdict);
                        testStep.FireExecutionCompleteEvent(testStep, testStepResult);
                    }
                }
            }
            else
            {
                testCaseResult.SetTestVerdict(TestVerdict.DidNotExecute);
                testCaseResult.SetTestMessage("The test case is set to \"Active\", however it does not contain active test steps.");
            }

            testCaseResult.SetEndTime(DateTime.Now);
            testCaseResult.FinalizeVerdict();

            // Restore preserved test property collection.
            Core.TestProperties.SetTestPropertyCollection(savedTestPropertyCollection);

            FireExecutionCompleteEvent(this, testCaseResult);

            return(testCaseResult);
        }