private string getStatisticsStringSuite(TestSuite suite) { string result = string.Empty; TestData.RefreshSuiteStatistics(suite); result += @"<div id=""suitestat"">"; int scPassed = 0; int scFailed = 0; int scNotTested = 0; foreach (TestScenario tsc in suite.TestScenarios) { switch (tsc.enStatus) { case TestScenarioStatuses.Passed: scPassed++; break; case TestScenarioStatuses.Failed: scFailed++; break; case TestScenarioStatuses.NotTested: scNotTested++; break; default: throw new Exception("Invalid value for TestScenarioStatuses"); } } // scenarios result += @"Scenarios:"; result += suite.TestScenarios.Count.ToString(); result += " Passed:"; result += scPassed.ToString(); result += " Failed:"; result += scFailed.ToString(); result += " Not tested:"; result += scNotTested.ToString(); result += newLineHTML; // test results result += @"Test cases:"; result += suite.Statistics.All.ToString(); result += " Passed:"; result += suite.Statistics.Passed.ToString(); result += " Failed:"; result += suite.Statistics.Failed.ToString(); result += " Not tested:"; result += suite.Statistics.NotTested.ToString(); result += " Time spent:"; result += Convert.ToInt32(suite.Statistics.TimeSpent).ToString(); result += @" seconds</div>"; return result; }
internal static bool AddTestScenario(TestSuite testSuite, string testScenarioName, string testScenarioId, string testScenarioDescription, string testSuiteName, string testSuiteId) { bool result = false; // clean up the last empty test result // in the previous scenario if (TestData.CurrentTestScenario != null) { if (TestData.CurrentTestScenario.TestResults.Count > 0) { if (TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Details.Count == 0 && TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Status == TestStateNotTested) { TestData.CurrentTestScenario.TestResults.RemoveAt(TestData.CurrentTestScenario.TestResults.Count - 1); } } // // 20130405 // if ((null != TestData.CurrentTestResult.Name && // string.Empty != TestData.CurrentTestResult.Name) || // (0 < TestData.CurrentTestResult.Details.Count)) { // //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; // } } // 20130301 // set time spent on the previous scenario if (null != TMX.TestData.CurrentTestScenario) { if (System.DateTime.MinValue != TMX.TestData.CurrentTestScenario.Timestamp) { TMX.TestData.CurrentTestScenario.SetTimeSpent( TMX.TestData.CurrentTestScenario.TimeSpent += (System.DateTime.Now - TMX.TestData.CurrentTestScenario.Timestamp).TotalSeconds); TMX.TestData.CurrentTestScenario.Timestamp = System.DateTime.MinValue; } } dumpTestStructure("2"); if (testSuite != null) { TestData.CurrentTestSuite = testSuite; } else if (testSuite == null && testSuiteName != string.Empty && testSuiteName != null) { TestSuite testSuite2 = GetTestSuite(testSuiteName, testSuiteId); if (testSuite2 != null) { TestData.CurrentTestSuite = testSuite2; } } else if (testSuite == null && testSuiteId != string.Empty && testSuiteId != null) { TestSuite testSuite3 = GetTestSuite(testSuiteName, testSuiteId); if (testSuite3 != null) { TestData.CurrentTestSuite = testSuite3; } } if (TestData.CurrentTestSuite == null) { return result; } if (testScenarioId == null || testScenarioId == string.Empty) { testScenarioId = GetTestScenarioId(); } dumpTestStructure("4"); // // 20130405 // if (null != TestData.TestSuites && 0 < TestData.TestSuites.Count) { // int lastTestSuiteNumber = TestData.TestSuites.Count - 1; // // if (null != TestData.TestSuites[lastTestSuiteNumber].TestScenarios && 0 < TestData.TestSuites[lastTestSuiteNumber].TestScenarios.Count) { // int lastTestScenarioNumber = TestData.TestSuites[lastTestSuiteNumber].TestScenarios.Count - 1; // // if (TestData.CurrentTestScenario.Name == TestData.TestSuites[lastTestSuiteNumber].TestScenarios[lastTestScenarioNumber].Name && // TestData.CurrentTestScenario.Id == TestData.TestSuites[lastTestSuiteNumber].TestScenarios[lastTestScenarioNumber].Id) { // // TestData.TestSuites[lastTestSuiteNumber].TestScenarios[lastTestScenarioNumber] = TestData.CurrentTestScenario; // } // } // } dumpTestStructure("4.4"); TestData.CurrentTestSuite.TestScenarios.Add( new TestScenario(testScenarioName, testScenarioId, TestData.CurrentTestSuite.Id)); //testSuiteId)); dumpTestStructure("4.5"); // description if (testScenarioDescription != null && testScenarioDescription != string.Empty) { TestData.CurrentTestSuite.TestScenarios[CurrentTestSuite.TestScenarios.Count - 1].Description = testScenarioDescription; } dumpTestStructure("4.6"); TestData.CurrentTestScenario = (TestScenario)TestData.CurrentTestSuite.TestScenarios[CurrentTestSuite.TestScenarios.Count - 1]; // 20130301 // set the initial time for this scenario's session CurrentTestScenario.SetNow(); OnTMXNewTestScenarioAdded(TestData.CurrentTestScenario, null); result = true; dumpTestStructure("7"); return result; }
internal static TestScenario GetTestScenario(TestSuite testSuite, string testScenarioName, string testScenarioId, string testSuiteName, string testSuiteId) { TestScenario result = null; if (testSuite != null) { TestData.CurrentTestSuite = testSuite; } else if (testSuite == null && testSuiteName != string.Empty && testSuiteName != null) { TestSuite testSuite2 = GetTestSuite(testSuiteName, testSuiteId); if (testSuite2 != null) { TestData.CurrentTestSuite = testSuite2; } } else if (testSuite == null && testSuiteId != string.Empty && testSuiteId != null) { TestSuite testSuite3 = GetTestSuite(testSuiteName, testSuiteId); if (testSuite3 != null) { TestData.CurrentTestSuite = testSuite3; } } if (TestData.CurrentTestSuite == null) { return result; } if (testScenarioName != null && testScenarioName != string.Empty) { foreach (TestScenario testScenario in TestData.CurrentTestSuite.TestScenarios) { if (testScenario.Name == testScenarioName) { TestData.CurrentTestScenario = testScenario; return testScenario; } } } if (testScenarioId != null && testScenarioId != string.Empty) { foreach (TestScenario testScenario in TestData.CurrentTestSuite.TestScenarios) { if (testScenario.Id == testScenarioId) { TestData.CurrentTestScenario = testScenario; return testScenario; } } } return result; }
internal static TestScenario GetTestScenario( TestSuite testSuite, string testScenarioName, string testScenarioId, string testSuiteName, string testSuiteId, string testPlatformId) { TestScenario result = null; if (testSuite != null) { TestData.CurrentTestSuite = testSuite; } else if (testSuite == null && testSuiteName != string.Empty && testSuiteName != null) { TestSuite testSuite2 = GetTestSuite(testSuiteName, testSuiteId, testPlatformId); if (testSuite2 != null) { TestData.CurrentTestSuite = testSuite2; } } else if (testSuite == null && testSuiteId != string.Empty && testSuiteId != null) { TestSuite testSuite3 = GetTestSuite(testSuiteName, testSuiteId, testPlatformId); if (testSuite3 != null) { TestData.CurrentTestSuite = testSuite3; } } if (TestData.CurrentTestSuite == null) { return result; } if (testScenarioName != null && testScenarioName != string.Empty) { foreach (TestScenario testScenario in TestData.CurrentTestSuite.TestScenarios) { if (testScenario.Name == testScenarioName) { TestData.CurrentTestScenario = testScenario; // 20130912 //return testScenario; return TestData.CurrentTestScenario; } } } if (testScenarioId != null && testScenarioId != string.Empty) { foreach (TestScenario testScenario in TestData.CurrentTestSuite.TestScenarios) { if (testScenario.Id == testScenarioId) { // 20130621 if (testPlatformId != testScenario.PlatformId) { continue; } else { // 20130912 //if (testScenarioName != testScenario.Name) { if (testScenarioName != testScenario.Name && null != testScenarioName && string.Empty != testScenarioName) { continue; } else { TestData.CurrentTestScenario = testScenario; return testScenario; } } // 20130621 // TestData.CurrentTestScenario = testScenario; // return testScenario; } } } return result; }
internal static TestStat RefreshSuiteStatistics(TestSuite suite, bool skipAutomatic) { TestStat ts = new TestStat(); foreach (TestScenario tsc in suite.TestScenarios) { // 20130322 //RefreshScenarioStatistics(tsc); RefreshScenarioStatistics(tsc, skipAutomatic); ts.All += tsc.Statistics.All; ts.Passed += tsc.Statistics.Passed; ts.Failed += tsc.Statistics.Failed; ts.NotTested += tsc.Statistics.NotTested; ts.TimeSpent += tsc.Statistics.TimeSpent; ts.PassedButWithBadSmell += tsc.Statistics.PassedButWithBadSmell; } suite.Statistics = ts; return ts; }
internal static TestCase GetTestCase( TestSuite testSuite, string testCaseName, string testCaseId, string testScenarioName, string testScenarioId, string testSuiteName, string testSuiteId, string testPlatformId) { TestCase result = null; if (null == testSuite) { testSuite = TMX.TestData.GetTestSuite( testSuiteName, testSuiteId, testPlatformId); } // 20130912 if (null == testSuite) { // better error description? return result; } TestScenario testScenario = null; if (null != testSuite) { testScenario = TMX.TestData.GetTestScenario( testSuite, testScenarioName, testScenarioId, testSuiteName, testSuiteId, testPlatformId); } // 20130912 if (null == testScenario) { // better error description? return result; } if (null != testScenario && 0 < testScenario.TestCases.Count) { foreach (TestCase testCase in testScenario.TestCases) { // 20130912 //if ((testCaseName == testCase.TestCaseName && // testCaseId == testCase.TestCaseId) || // (null == testCaseName && testCaseId == testCase.TestCaseId) || // (null == testCaseId && testCaseName == testCase.TestCaseName)){ if ((testCaseName == testCase.TestCaseName && testCaseId == testCase.TestCaseId) || ((null == testCaseName || string.Empty == testCaseName) && testCaseId == testCase.TestCaseId) || ((null == testCaseId || string.Empty == testCaseId) && testCaseName == testCase.TestCaseName)){ result = testCase; break; } } } return result; }
internal static TestCase GetTestCase( TestSuite testSuite, string testCaseName, string testCaseId, string testScenarioName, string testScenarioId, string testSuiteName, string testSuiteId, string testPlatformId) { TestCase result = null; if (null == testSuite) { testSuite = TMX.TestData.GetTestSuite( testSuiteName, testSuiteId, testPlatformId); } TestScenario testScenario = null; if (null != testSuite) { testScenario = TMX.TestData.GetTestScenario( testSuite, testScenarioName, testScenarioId, testSuiteName, testSuiteId, testPlatformId); } if (null != testScenario && 0 < testScenario.TestCases.Count) { foreach (TestCase testCase in testScenario.TestCases) { if ((testCaseName == testCase.TestCaseName && testCaseId == testCase.TestCaseId) || (null == testCaseName && testCaseId == testCase.TestCaseId) || (null == testCaseId && testCaseName == testCase.TestCaseName)){ result = testCase; break; } } } return result; }
internal static bool AddTestScenario(TestSuite testSuite, string testScenarioName, string testScenarioId, string testScenarioDescription, string testSuiteName, string testSuiteId, string testPlatformId, ScriptBlock[] testScenarioBeforeTest, ScriptBlock[] testScenarioAfterTest) { bool result = false; // clean up the last empty test result // in the previous scenario if (TestData.CurrentTestScenario != null) { if (TestData.CurrentTestScenario.TestResults.Count > 0) { if (TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Details.Count == 0 && TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Status == TestStateNotTested) { TestData.CurrentTestScenario.TestResults.RemoveAt(TestData.CurrentTestScenario.TestResults.Count - 1); } } // // 20130405 // if ((null != TestData.CurrentTestResult.Name && // string.Empty != TestData.CurrentTestResult.Name) || // (0 < TestData.CurrentTestResult.Details.Count)) { // //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; // } } // 20130301 // set time spent on the previous scenario if (null != TMX.TestData.CurrentTestScenario) { if (System.DateTime.MinValue != TMX.TestData.CurrentTestScenario.Timestamp) { TMX.TestData.CurrentTestScenario.SetTimeSpent( TMX.TestData.CurrentTestScenario.TimeSpent += (System.DateTime.Now - TMX.TestData.CurrentTestScenario.Timestamp).TotalSeconds); TMX.TestData.CurrentTestScenario.Timestamp = System.DateTime.MinValue; } } dumpTestStructure("2"); if (testSuite != null) { TestData.CurrentTestSuite = testSuite; } else if (!string.IsNullOrEmpty(testSuiteName)) { /* } else if (testSuite == null && testSuiteName != string.Empty && testSuiteName != null) { */ TestSuite testSuite2 = GetTestSuite(testSuiteName, testSuiteId, testPlatformId); if (testSuite2 != null) { TestData.CurrentTestSuite = testSuite2; } } else if (!string.IsNullOrEmpty(testSuiteId)) { /* } else if (testSuite == null && testSuiteId != string.Empty && testSuiteId != null) { */ TestSuite testSuite3 = GetTestSuite(testSuiteName, testSuiteId, testPlatformId); if (testSuite3 != null) { TestData.CurrentTestSuite = testSuite3; } } if (TestData.CurrentTestSuite == null) { return result; } if (string.IsNullOrEmpty(testScenarioId)) { testScenarioId = GetTestScenarioId(); } /* if (testScenarioId == null || testScenarioId == string.Empty) { testScenarioId = GetTestScenarioId(); } */ dumpTestStructure("4"); // // 20130405 // if (null != TestData.TestSuites && 0 < TestData.TestSuites.Count) { // int lastTestSuiteNumber = TestData.TestSuites.Count - 1; // // if (null != TestData.TestSuites[lastTestSuiteNumber].TestScenarios && 0 < TestData.TestSuites[lastTestSuiteNumber].TestScenarios.Count) { // int lastTestScenarioNumber = TestData.TestSuites[lastTestSuiteNumber].TestScenarios.Count - 1; // // if (TestData.CurrentTestScenario.Name == TestData.TestSuites[lastTestSuiteNumber].TestScenarios[lastTestScenarioNumber].Name && // TestData.CurrentTestScenario.Id == TestData.TestSuites[lastTestSuiteNumber].TestScenarios[lastTestScenarioNumber].Id) { // // TestData.TestSuites[lastTestSuiteNumber].TestScenarios[lastTestScenarioNumber] = TestData.CurrentTestScenario; // } // } // } dumpTestStructure("4.4"); TestData.CurrentTestSuite.TestScenarios.Add( new TestScenario(testScenarioName, testScenarioId, TestData.CurrentTestSuite.Id)); //testSuiteId)); dumpTestStructure("4.5"); // description if (!string.IsNullOrEmpty(testScenarioDescription)) { TestData.CurrentTestSuite.TestScenarios[CurrentTestSuite.TestScenarios.Count - 1].Description = testScenarioDescription; } /* if (testScenarioDescription != null && testScenarioDescription != string.Empty) { TestData.CurrentTestSuite.TestScenarios[CurrentTestSuite.TestScenarios.Count - 1].Description = testScenarioDescription; } */ dumpTestStructure("4.6"); TestData.CurrentTestScenario = (TestScenario)TestData.CurrentTestSuite.TestScenarios[CurrentTestSuite.TestScenarios.Count - 1]; // 20130615 // 20130616 TMX.TestData.CurrentTestScenario.BeforeTest = testScenarioBeforeTest; TMX.TestData.CurrentTestScenario.AfterTest = testScenarioAfterTest; // // 20130531 // try { // // TestData.CurrentTestScenario.PlatformId = // TestData.CurrentTestPlatform.Id; // } // catch { // // } // 20130612 TestData.CurrentTestScenario.PlatformId = !string.IsNullOrEmpty(testPlatformId) ? testPlatformId : TestData.CurrentTestSuite.PlatformId; /* if (null != testPlatformId && string.Empty != testPlatformId) { TestData.CurrentTestScenario.PlatformId = testPlatformId; } else { TestData.CurrentTestScenario.PlatformId = //TestData.CurrentTestPlatform.Id; TestData.CurrentTestSuite.PlatformId; } */ // 20130301 // set the initial time for this scenario's session CurrentTestScenario.SetNow(); OnTmxNewTestScenarioAdded(TestData.CurrentTestScenario, null); if (TMX.Preferences.Storage) { // 20130527 using (var session = StorageHelper.SessionFactory.OpenSession()) { session.Save(TestData.CurrentTestScenario); } } result = true; dumpTestStructure("7"); return result; }
internal static bool AddTestScenario(TestSuite testSuite, string testScenarioName, string testScenarioId, string testScenarioDescription, string testSuiteName, string testSuiteId) { bool result = false; // clean up the last empty test result // in the previous scenario if (TestData.CurrentTestScenario != null) { if (TestData.CurrentTestScenario.TestResults.Count > 0) { if (TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Details.Count == 0 && TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Status == TestStateNotTested) { TestData.CurrentTestScenario.TestResults.RemoveAt(TestData.CurrentTestScenario.TestResults.Count - 1); } } } // 20130301 // set time spent on the previous scenario if (null != TMX.TestData.CurrentTestScenario) { if (System.DateTime.MinValue != TMX.TestData.CurrentTestScenario.Timestamp) { TMX.TestData.CurrentTestScenario.SetTimeSpent( TMX.TestData.CurrentTestScenario.TimeSpent += (System.DateTime.Now - TMX.TestData.CurrentTestScenario.Timestamp).TotalSeconds); TMX.TestData.CurrentTestScenario.Timestamp = System.DateTime.MinValue; } } if (testSuite != null) { TestData.CurrentTestSuite = testSuite; } else if (testSuite == null && testSuiteName != string.Empty && testSuiteName != null) { TestSuite testSuite2 = GetTestSuite(testSuiteName, testSuiteId); if (testSuite2 != null) { TestData.CurrentTestSuite = testSuite2; } } else if (testSuite == null && testSuiteId != string.Empty && testSuiteId != null) { TestSuite testSuite3 = GetTestSuite(testSuiteName, testSuiteId); if (testSuite3 != null) { TestData.CurrentTestSuite = testSuite3; } } if (TestData.CurrentTestSuite == null) { return result; } if (testScenarioId == null || testScenarioId == string.Empty) { testScenarioId = GetTestScenarioId(); } TestData.CurrentTestSuite.TestScenarios.Add( new TestScenario(testScenarioName, testScenarioId, TestData.CurrentTestSuite.Id)); //testSuiteId)); // description if (testScenarioDescription != null && testScenarioDescription != string.Empty) { TestData.CurrentTestSuite.TestScenarios[CurrentTestSuite.TestScenarios.Count - 1].Description = testScenarioDescription; } TestData.CurrentTestScenario = (TestScenario)TestData.CurrentTestSuite.TestScenarios[CurrentTestSuite.TestScenarios.Count - 1]; // 20130301 // set the initial time for this scenario's session CurrentTestScenario.SetNow(); OnTMXNewTestScenarioAdded(TestData.CurrentTestScenario, null); result = true; return result; }
public void RunTestCase( TestCaseExecCmdletBase cmdlet, TestSuite testSuite, TestScenario testScenario) { ITestCase testCase = TMX.TestData.GetTestCase( testSuite, string.Empty, //cmdlet.Name cmdlet.Id, testScenario.Name, testScenario.Id, testSuite.Name, testSuite.Id, testScenario.PlatformId); if (null == testCase) { return; } // run BeforeScenario scriptblocks //if (null != testSuite) { if (null != testSuite && null != testScenario) { cmdlet.runTwoScriptBlockCollections( testSuite.BeforeScenario, null, // alternate scriptblocks cmdlet, testSuite.BeforeScenarioParameters); } // run BeforeTest scriptblocks if (null != testScenario) { cmdlet.runTwoScriptBlockCollections( testScenario.BeforeTest, null, // alternate scriptblocks cmdlet, testScenario.BeforeTestParameters); } // run TestCode scriptblocks cmdlet.runTwoScriptBlockCollections( //cmdlet.TestCode, testCase.TestCode, null, cmdlet, cmdlet.TestCodeParameters); // run AfterTest scriptblocks if (null != testScenario) { cmdlet.runTwoScriptBlockCollections( testScenario.AfterTest, null, // alternate scriptblocks cmdlet, testScenario.AfterTestParameters); } // run AfterScenario scriptblocks //if (null != testSuite) { if (null != testSuite && null != testScenario) { cmdlet.runTwoScriptBlockCollections( testSuite.AfterScenario, null, // alternate scriptblocks cmdlet, testSuite.AfterScenarioParameters); } }