Description of TestResult.
Inheritance: ITestResult
Esempio n. 1
0
        // 20160116
        internal static void AddTestResult(string closingTestResultName, // previousTestResultName
                                           string closingTestResultId, // previousTestResultId
                                           bool? passed,
                                           bool isKnownIssue,
                                           bool generateNextResult,
                                           // 20160116
                                           // InvocationInfo myInvocation,
                                           // ErrorRecord error,
                                           Exception error,
                                           string testResultDescription,
                                           TestResultOrigins origin,
                                           bool skipAutomatic)
        {
            //TestData.InitCurrentTestScenario();
            
            bool generated = TestResultOrigins.Automatic == origin;
            
            ITestResult currentTestResult;
            if (null != TestData.CurrentTestResult) {
                currentTestResult = TestData.CurrentTestResult;
            } else {
                // 20141204
//                currentTestResult =
//                    new TestResult(
//                        TestData.CurrentTestScenario.Id,
//                        TestData.CurrentTestSuite.Id);
                currentTestResult =
                    new TestResult(
                        TestData.CurrentTestScenario.Id,
                        TestData.CurrentTestSuite.Id) {
                    SuiteUniqueId = TestData.CurrentTestSuite.UniqueId,
                    ScenarioUniqueId = TestData.CurrentTestScenario.UniqueId
                };
            }
            
            if (string.IsNullOrEmpty(currentTestResult.Name)) {
                
//                if (closingTestResultName != null &&
//                    closingTestResultName != string.Empty &&
//                    closingTestResultName.Length > 0 &&
//                    TestData.CurrentTestResult != null && 
//                     closingTestResultName != TestData.CurrentTestResult.Name) {

                if (!string.IsNullOrEmpty(closingTestResultName) &&
                    ((TestData.CurrentTestResult != null && 
                      closingTestResultName != TestData.CurrentTestResult.Name) ||
                      null == TestData.CurrentTestResult)) {
                    
                    currentTestResult.Name = closingTestResultName;
                } else {
                    currentTestResult.Name = "generated test result name";
                }
                
            } else {
                // the current test result is a result that was preset
                // nothing to do
            }

            // setting test result's origin
            if (generated)
                currentTestResult.SetOrigin(TestResultOrigins.Automatic);
            else
                currentTestResult.SetOrigin(origin);

            if (string.IsNullOrEmpty(currentTestResult.Id)) {
                
                if (!string.IsNullOrEmpty(closingTestResultId) &&
                    ((null != TestData.CurrentTestResult &&
                    closingTestResultId != TestData.CurrentTestResult.Id) ||
                    null == TestData.CurrentTestResult))
                    currentTestResult.Id = closingTestResultId;
                else
                    currentTestResult.Id = GetTestResultId();
            } else {
                // there already was the Id
                // nothing to do
            }
            
            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 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) {
                    
                    foreach (ITestResultDetail detail in currentTestResult.Details) {
                        if (null == ((TestResultDetail)detail).ErrorDetail) {
                            noErrors = false;
                            break;
                        }
                    }
                }
                
                if (noErrors && null != passed) {
                    currentTestResult.enStatus = TestResultStatuses.Passed;
                }

            }
            
            if (!string.IsNullOrEmpty(testResultDescription)) {
                currentTestResult.Description = testResultDescription;
            }
            
            if (generated)
                currentTestResult.SetGenerated();
            
            if (TmxHelper.TestCaseStarted == DateTime.MinValue)
                TmxHelper.TestCaseStarted = DateTime.Now;

            currentTestResult.SetNow();
            currentTestResult.SetTimeSpent(
                (currentTestResult.Timestamp - TmxHelper.TestCaseStarted).TotalSeconds);
            
            TestData.CurrentTestResult = currentTestResult;
            
            try {
                TestData.CurrentTestResult.PlatformUniqueId = TestData.CurrentTestScenario.PlatformUniqueId;
                CurrentTestResult.PlatformId = CurrentTestScenario.PlatformId;
                // 20141204
                CurrentTestResult.SuiteUniqueId = CurrentTestSuite.UniqueId;
                CurrentTestResult.ScenarioUniqueId = CurrentTestScenario.UniqueId;
            }
            catch {}
            
            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 &&
                !string.IsNullOrEmpty(TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Name)) {
                
                TmxHelper.TestCaseStarted = DateTime.Now;
                // 20141204
                // TestData.CurrentTestScenario.TestResults.Add(new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id));
                TestData.CurrentTestScenario.TestResults.Add(new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id) {
                                                                 SuiteUniqueId = TestData.CurrentTestSuite.UniqueId,
                                                                 ScenarioUniqueId = TestData.CurrentTestScenario.UniqueId
                                                             });
            }

            /*
            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) {
                
                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
            // 20160116
            /*
            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) {
                // 20150116
                // TestData.CurrentTestResult.SetError(error);
                TestData.CurrentTestResult.SetError(error.Exception);
            }
            */
            #endregion Test Result's PowerShell data
            
            var sourceTestResult = TestData.CurrentTestResult;
            SetScenarioStatus(skipAutomatic);
            SetSuiteStatus(skipAutomatic);
            
            if (generateNextResult) {
                // write current time
                TmxHelper.TestCaseStarted = DateTime.Now;
                TestData.CurrentTestScenario.TestResults.Add(
                    new TestResult(
                       TestData.CurrentTestScenario.Id,
                       TestData.CurrentTestScenario.SuiteId) { SuiteUniqueId = CurrentTestScenario.SuiteUniqueId, ScenarioUniqueId = CurrentTestScenario.UniqueId });
                TestData.CurrentTestResult = 
                    TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1];
            } else {
                // write zero time
                TmxHelper.TestCaseStarted = DateTime.MinValue;
                TestData.CurrentTestResult = null;
            }
            
            if (Preferences.Storage) {
                using (var session = StorageHelper.SessionFactory.OpenSession())
                {
                    session.Save(TestData.CurrentTestResult);
                }
            }

            OnTmxNewTestResultClosed(sourceTestResult, null);
        }
Esempio n. 2
0
//        internal static bool AttachTestResultCode()
//        {
//            bool result = false;
//            
//            
//            
//            return result;
//        }
        
        internal static void AddTestResultTextDetail(ITestResultDetailCmdletBaseDataObject 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:
                    if (TestResultStatuses.KnownIssue != CurrentTestResult.enStatus)
                        CurrentTestResult.enStatus = TestResultStatuses.Failed;
                    break;
                case TestResultStatuses.Passed:
                    if (TestResultStatuses.KnownIssue != CurrentTestResult.enStatus &&
                    TestResultStatuses.Failed != CurrentTestResult.enStatus)
                        CurrentTestResult.enStatus = TestResultStatuses.Passed;
                    break;
                case TestResultStatuses.NotTested:
                    // nothing to do
                    break;
                case TestResultStatuses.KnownIssue:
                    CurrentTestResult.enStatus = TestResultStatuses.KnownIssue;
                    break;
                default:
//                    cmdlet.WriteVerbose(cmdlet, "TestResultStatus = ????");
//                    cmdlet.WriteVerbose(cmdlet, cmdlet.TestResultStatus.ToString());
                    break;
            }
            
            OnTmxNewTestResultDetailAdded(testResultDetail, null);
            
            if (cmdlet.Finished) {
                
                TmxHelper.TestCaseStarted = 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;
                }
            }
        }
Esempio n. 3
0
        List<ITestResult> importTestResults(IEnumerable<XElement> testResultElements, string suiteId, Guid suiteUniqueId, string scenarioId, Guid scenarioUniqueId)
        {
            var importedTestResults = new List<ITestResult>();
            if (null == testResultElements) return importedTestResults;
            
            foreach (var testResultElement in testResultElements) {
                // 20150127
                // bool passedValue = false;
                // bool knownIssueValue = false;
                // passedValue |= "PASSED" == getStringAttribute(testResultElement, "status");
                // knownIssueValue |= "KNOWN ISSUE" == getStringAttribute(testResultElement, "status");
//                var status = ("PASSED" == getStringAttribute(testResultElement, "status")) ? TestResultStatuses.Passed :
//                    ("FAILED" == getStringAttribute(testResultElement, "status")) ? TestResultStatuses.Failed :
//                    ("KNOWN ISSUE" == getStringAttribute(testResultElement, "status")) ? TestResultStatuses.KnownIssue : TestResultStatuses.NotTested;
                // TestResultStatuses status;
                // var testResultElement = gettestResultStatus(out status);
                var status = gettestResultStatus(testResultElement);
                TestResultOrigins origin = TestResultOrigins.Logical;
                if ("TECHNICAL" == getStringAttribute(testResultElement, "origin").ToUpper())
                    origin = TestResultOrigins.Technical;
                if ("AUTOMATIC" == getStringAttribute(testResultElement, "origin").ToUpper())
                    origin = TestResultOrigins.Automatic;
                // if ((TestResultOrigins.Technical == origin) &&
                //     passedValue) {
                if ((TestResultOrigins.Technical == origin) && TestResultStatuses.Passed == status) {
                    continue;
                }
                string testResultDescription = string.Empty;
                testResultDescription = getStringAttribute(testResultElement, "description");
                
                bool addTestResult = false;
                var testResult = importedTestResults.FirstOrDefault(tr => tr.Id == getStringAttribute(testResultElement, "id") &&
                                                           tr.Name == getStringAttribute(testResultElement, "name"));

                if (null == testResult) {
                    testResult = new TestResult {
                        UniqueId = getGuidAttribute(testResultElement, "uniqueId"),
                        Id = getStringAttribute(testResultElement, "id"),
                        Name = getStringAttribute(testResultElement, "name"),
                        Description = testResultDescription,
                        // 20150127
                        // enStatus = (!passedValue ? TestResultStatuses.Failed : knownIssueValue ? TestResultStatuses.KnownIssue : passedValue ? TestResultStatuses.Passed : TestResultStatuses.NotTested),
                        enStatus = status,
                        SuiteId = suiteId,
                        ScenarioId = scenarioId,
                        SuiteUniqueId = suiteUniqueId,
                        ScenarioUniqueId = scenarioUniqueId
                    };
                    addTestResult = true;
                }
                // TODO: DI
                (testResult as TestResult).SetTimestamp(getDateTimeAttribute(testResultElement, "timestamp"));
                testResult.SetOrigin(origin);
                testResult.SetTimeSpent(getDoubleAttribute(testResultElement, "timeSpent"));
                testResult.PlatformId = getStringAttribute(testResultElement, "platformId");
                testResult.PlatformUniqueId = getGuidAttribute(testResultElement, "platformUniqueId");
                try {
                    var testResultDetails = from testResultDetail in testResultElement.Descendants("detail")
                                            select testResultDetail;
                    testResult.Details.AddRange(importTestResultDetails(testResultDetails)); // , testResult);
                } catch (Exception e) {
                    //                                cmdlet.WriteVerbose(cmdlet, eImportDetails);
                }
                if (addTestResult)
                    importedTestResults.Add(testResult);
            }
            return importedTestResults;
        }