示例#1
0
 private string getStatisticsStringTestResult(TestResult testResult)
 {
     string result = string.Empty;
     result += @"<div id=""testresultstat"">Time spent:";
     result += Convert.ToInt32(testResult.TimeSpent).ToString();
     result += @" seconds</div>";
     return result;
 }
示例#2
0
文件: TestData.cs 项目: suriyel/STUPS
        // 20130331
        //internal static void AddTestResultTextDetail(object detail)
        internal static void AddTestResultTextDetail(TestResultDetailCmdletBase cmdlet, object detail)
        {
            ITestResultDetail testResultDetail =
                new TestResultDetail();

            testResultDetail.AddTestResultDetail(
                TestResultDetailTypes.Comment,
                detail.ToString());
            CurrentTestResult.Details.Add(testResultDetail);

            testResultDetail.DetailStatus = cmdlet.TestResultStatus;

            switch (cmdlet.TestResultStatus) {
                case TestResultStatuses.Failed:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = Failed");
                    if (TestResultStatuses.KnownIssue != CurrentTestResult.enStatus) {

                        CurrentTestResult.enStatus = TestResultStatuses.Failed;
                    }
                    break;
                case TestResultStatuses.Passed:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = Passed");
                    if (TestResultStatuses.KnownIssue != CurrentTestResult.enStatus &&
                        TestResultStatuses.Failed != CurrentTestResult.enStatus) {

                        CurrentTestResult.enStatus = TestResultStatuses.Passed;
                    }
                    break;
                case TestResultStatuses.NotTested:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = NotTested");
                    // nothing to do
                    break;
                case TestResultStatuses.KnownIssue:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = KnownIssue");
                    CurrentTestResult.enStatus = TestResultStatuses.KnownIssue;
                    break;
                default:
                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = ????");
                    cmdlet.WriteVerbose(cmdlet, cmdlet.TestResultStatus.ToString());
                    break;
            }

            OnTMXNewTestResultDetailAdded(testResultDetail, null);

            // 20130402
            if (cmdlet.Finished) {

                TMXHelper.TestCaseStarted =
                    System.DateTime.Now;

                // 20130621
            //                TestData.CurrentTestScenario.TestResults.Add(new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id));
            //                TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] =
            //                    TestData.CurrentTestResult;
                // 20130621
                ITestResult newTestResult = new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id);
                if (TestData.CurrentTestResult == TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1]) {
                    // autogeneration + Close-TMXTestResult
                    TestData.CurrentTestScenario.TestResults.Add(newTestResult);
                    TestData.CurrentTestResult = TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1];
                } else {
                    // Set-TMXCurrentTestResult + any closing
                    TestData.CurrentTestScenario.TestResults.Add(TestData.CurrentTestResult);
                    TestData.CurrentTestResult = newTestResult;
                }
            }
        }
示例#3
0
        internal static void AddTestResult(string closingTestResultName, // previousTestResultName
                                           string closingTestResultId, // previousTestResultId
                                           bool? passed,
                                           bool isKnownIssue,
                                           bool generateNextResult,
                                           InvocationInfo myInvocation,
                                           ErrorRecord error,
                                           string testResultDescription,
                                           // 20130322
                                           //bool generated)
                                           bool generated,
                                           bool skipAutomatic)
        {
            TestData.InitCurrentTestScenario();

            ITestResult currentTestResult;
            if (null != TestData.CurrentTestResult) {
            dumpTestStructure("AddTestResult #1");
                currentTestResult = TestData.CurrentTestResult;
            dumpTestStructure("AddTestResult #1b");
            } else {
            dumpTestStructure("AddTestResult #2");
                currentTestResult =
                    new TestResult(
                        TestData.CurrentTestScenario.Id,
                        TestData.CurrentTestSuite.Id);
            dumpTestStructure("AddTestResult #2b");
            }

            // 20130325
            if (null == currentTestResult.Name ||
                string.Empty == currentTestResult.Name ||
                0 == currentTestResult.Name.Length) {
            dumpTestStructure("AddTestResult #3");
                if (closingTestResultName != null &&
                    closingTestResultName != string.Empty &&
                    closingTestResultName.Length > 0 &&
                    TMX.TestData.CurrentTestResult != null &&
                     closingTestResultName != TMX.TestData.CurrentTestResult.Name) {
            dumpTestStructure("AddTestResult #3b");
                    currentTestResult.Name = closingTestResultName;

                } else {
            dumpTestStructure("AddTestResult #4");
                    currentTestResult.Name = "generated test result name";
                }

            // 20130326
            } else {
            dumpTestStructure("AddTestResult #5");
                // the current test result is a result that was preset
                // nothing to do
            }

            // 20130322
            // setting test result's origin
            if (generated) {
            dumpTestStructure("AddTestResult #6");
                currentTestResult.SetOrigin(TestResultOrigins.Automatic);

            } else {
            dumpTestStructure("AddTestResult #7");
                currentTestResult.SetOrigin(TestResultOrigins.Logical);

            }

            // 20130325
            if (null == currentTestResult.Id ||
                string.Empty == currentTestResult.Id ||
                0 == currentTestResult.Id.Length) {
            dumpTestStructure("AddTestResult #8");
                if (closingTestResultId != null &&
                    closingTestResultId != string.Empty &&
                    closingTestResultId.Length > 0 &&
                    null != TMX.TestData.CurrentTestResult &&
                    closingTestResultId != TMX.TestData.CurrentTestResult.Id) {
            dumpTestStructure("AddTestResult #9");
                    currentTestResult.Id = closingTestResultId;

                } else {
            dumpTestStructure("AddTestResult #10");
                    currentTestResult.Id = GetTestResultId();

                }
            // 20130326
            } else {
            dumpTestStructure("AddTestResult #11");
                // there already was the Id
                // nothing to do
            }

            if (passed != null) {
            dumpTestStructure("AddTestResult #14");
                if ((bool)passed) {

                    currentTestResult.enStatus = TestResultStatuses.Passed;
                } else {

                    currentTestResult.enStatus = TestResultStatuses.Failed;
                }

                if (isKnownIssue) {

                    currentTestResult.enStatus = TestResultStatuses.KnownIssue;
                }
            } else {
            dumpTestStructure("AddTestResult #15");

                // 20130407
                //currentTestResult.enStatus = TestResultStatuses.NotTested;

                // 20130330
                // if there were no errors during the test case execution
                // it is marked as passed
                bool noErrors = true;
                if (null == currentTestResult.Error &&
                    TestResultStatuses.Failed != currentTestResult.enStatus &&
                    TestResultStatuses.KnownIssue != currentTestResult.enStatus) {
            dumpTestStructure("AddTestResult #16");
                    //foreach (ITestResultDetail detail in currentTestResult.Details) {
                    foreach (ITestResultDetail detail in currentTestResult.Details) {
            dumpTestStructure("AddTestResult #17");
                        if (null == ((TestResultDetail)detail).ErrorDetail) {
            dumpTestStructure("AddTestResult #18");
                            noErrors = false;
                            break;
                        }
                    }
                }
                // 20130407
                //if (noErrors) {
                if (noErrors && null != passed) {
            dumpTestStructure("AddTestResult #19");
                    currentTestResult.enStatus = TestResultStatuses.Passed;
                }

            }
            dumpTestStructure("AddTestResult #20");
            if (testResultDescription != null &&
                testResultDescription != string.Empty &&
                testResultDescription.Length > 0){
            dumpTestStructure("AddTestResult #21");
                currentTestResult.Description = testResultDescription;

            }

            if (generated) {
            dumpTestStructure("AddTestResult #23");
                currentTestResult.SetGenerated();

            }

            if (TMXHelper.TestCaseStarted == System.DateTime.MinValue) {
            dumpTestStructure("AddTestResult #25");
                TMXHelper.TestCaseStarted = System.DateTime.Now;
            }

            currentTestResult.SetNow();
            dumpTestStructure("AddTestResult #27");
            currentTestResult.SetTimeSpent(
                (currentTestResult.Timestamp - TMXHelper.TestCaseStarted).TotalSeconds);
            dumpTestStructure("AddTestResult #29");
            TestData.CurrentTestResult = currentTestResult;

            // 20130326
            if (null != TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] &&
                TestResultOrigins.Logical == TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Origin &&
                TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] != TestData.CurrentTestResult &&
                null != TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Name &&
                0 < TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Name.Length) {
            dumpTestStructure("AddTestResult #30");
                TMXHelper.TestCaseStarted =
                    System.DateTime.Now;
                TestData.CurrentTestScenario.TestResults.Add(new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id));

            }

            TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] =
                TestData.CurrentTestResult;

            #region Test Result's PowerShell data
            if (myInvocation != null) {

                TestData.CurrentTestResult.SetScriptName(TMXHelper.GetScriptName(myInvocation));

                TestData.CurrentTestResult.SetLineNumber(TMXHelper.GetScriptLineNumber(myInvocation));

                TestData.CurrentTestResult.SetPosition(TMXHelper.GetPipelinePosition(myInvocation));

                // 20130329
                try {
                    if (((bool)passed && Preferences.LogScriptName_Passed) || (!(bool)passed && Preferences.LogScriptName_Failed)) {

                        TestData.CurrentTestResult.Code +=
                            "script name: " +
                            TestData.CurrentTestResult.ScriptName;

                    }
                }
                catch {}
                try {
                    if (((bool)passed && Preferences.LogLineNumber_Passed) || (!(bool)passed && Preferences.LogLineNumber_Failed)) {

                        TestData.CurrentTestResult.Code +=
                            "\r\nline number: " +
                            TestData.CurrentTestResult.LineNumber.ToString();

                    }
                }
                catch {}
                try {
                    if (((bool)passed && Preferences.LogCode_Passed) || (!(bool)passed && Preferences.LogCode_Failed)) {

                        TestData.CurrentTestResult.Code +=
                            "\r\ncode:\r\n" +
                            myInvocation.Line;

                    }
                }
                catch {}
            }

            if (error != null) {

                TestData.CurrentTestResult.SetError(error);

            }
            #endregion Test Result's PowerShell data

            var sourceTestResult = TestData.CurrentTestResult;

            // 20130322
            //SetScenarioStatus();
            SetScenarioStatus(skipAutomatic);

            // 20130322
            //SetSuiteStatus();
            SetSuiteStatus(skipAutomatic);

            if (generateNextResult) {
            dumpTestStructure("AddTestResult #40");
                // write current time
                TMXHelper.TestCaseStarted =
                    System.DateTime.Now;
                TestData.CurrentTestScenario.TestResults.Add(
                    new TestResult(
                       TestData.CurrentTestScenario.Id,
                       TestData.CurrentTestScenario.SuiteId));
                TestData.CurrentTestResult =
                    TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1];
            dumpTestStructure("AddTestResult #45");
            } else {
            dumpTestStructure("AddTestResult #46");
                // write zero time
                TMXHelper.TestCaseStarted =
                    System.DateTime.MinValue;
                TestData.CurrentTestResult = null;
            }

            OnTMXNewTestResultClosed(sourceTestResult, null);
        }
示例#4
0
        internal static void AddTestResult(string previousTestResultName,
                                           string previousTestResultId,
                                           bool? passed,
                                           bool isKnownIssue,
                                           bool generateNextResult,
                                           InvocationInfo myInvocation,
                                           ErrorRecord error,
                                           string testResultDescription,
                                           bool generated)
        {
            TestData.InitCurrentTestScenario();

            ITestResult currentTestResult;
            if (null != TestData.CurrentTestResult) {
                currentTestResult = TestData.CurrentTestResult;
            } else {

                currentTestResult =
                    new TestResult(
                        TestData.CurrentTestScenario.Id,
                        TestData.CurrentTestSuite.Id);
            }

            if (previousTestResultName != null &&
                previousTestResultName != string.Empty &&
                previousTestResultName.Length > 0 &&
                TMX.TestData.CurrentTestResult != null &&
                 previousTestResultName != TMX.TestData.CurrentTestResult.Name) {

                currentTestResult.Name = previousTestResultName;

            } else {

                currentTestResult.Name = "generated test result name";
            }

            if (previousTestResultId != null &&
                previousTestResultId != string.Empty &&
                previousTestResultId.Length > 0 &&

                null != TMX.TestData.CurrentTestResult &&
                previousTestResultId != TMX.TestData.CurrentTestResult.Id) {

                currentTestResult.Id = previousTestResultId;
            } else {

                currentTestResult.Id = GetTestResultId();
            }

            if (passed != null) {

                if ((bool)passed) {

                    currentTestResult.enStatus = TestResultStatuses.Passed;
                } else {

                    currentTestResult.enStatus = TestResultStatuses.Failed;
                }

                if (isKnownIssue) {

                    currentTestResult.enStatus = TestResultStatuses.KnownIssue;
                }
            } else {

                currentTestResult.enStatus = TestResultStatuses.NotTested;
            }

            if (testResultDescription != null &&
                testResultDescription != string.Empty &&
                testResultDescription.Length > 0){

                currentTestResult.Description = testResultDescription;

            }

            if (generated) {

                currentTestResult.SetGenerated();
            }

            if (TMXHelper.TestCaseStarted == System.DateTime.MinValue) {

                TMXHelper.TestCaseStarted = System.DateTime.Now;
            }

            currentTestResult.SetNow();
            currentTestResult.SetTimeSpent(
                (currentTestResult.Timestamp - TMXHelper.TestCaseStarted).TotalSeconds);

            TestData.CurrentTestResult = currentTestResult;

            TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] =
                TestData.CurrentTestResult;

            #region Test Result's PowerShell data
            if (myInvocation != null) {

                TestData.CurrentTestResult.SetScriptName(TMXHelper.GetScriptName(myInvocation));
                TestData.CurrentTestResult.SetLineNumber(TMXHelper.GetScriptLineNumber(myInvocation));
                TestData.CurrentTestResult.SetPosition(TMXHelper.GetPipelinePosition(myInvocation));
                if (((bool)passed && Preferences.LogScriptName_Passed) || (!(bool)passed && Preferences.LogScriptName_Failed)) {
                    TestData.CurrentTestResult.Code +=
                        "script name: " +
                        TestData.CurrentTestResult.ScriptName;
                }
                if (((bool)passed && Preferences.LogLineNumber_Passed) || (!(bool)passed && Preferences.LogLineNumber_Failed)) {
                    TestData.CurrentTestResult.Code +=
                        "\r\nline number: " +
                        TestData.CurrentTestResult.LineNumber.ToString();
                }
                if (((bool)passed && Preferences.LogCode_Passed) || (!(bool)passed && Preferences.LogCode_Failed)) {
                    TestData.CurrentTestResult.Code +=
                        "\r\ncode:\r\n" +
                        myInvocation.Line;
                }
            }

            if (error != null) {

                TestData.CurrentTestResult.SetError(error);
            }
            #endregion Test Result's PowerShell data

            var sourceTestResult = TestData.CurrentTestResult;

            SetScenarioStatus();

            SetSuiteStatus();

            if (generateNextResult) {

                // write current time
                TMXHelper.TestCaseStarted =
                    System.DateTime.Now;
                TestData.CurrentTestScenario.TestResults.Add(
                    new TestResult(
                       TestData.CurrentTestScenario.Id,
                       TestData.CurrentTestScenario.SuiteId));
                TestData.CurrentTestResult =
                    TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1];
            } else {

                // write zero time
                TMXHelper.TestCaseStarted =
                    System.DateTime.MinValue;
                TestData.CurrentTestResult = null;
            }
            OnTMXNewTestResultClosed(sourceTestResult, null);
        }