/// <summary> /// Begins the variation. /// </summary> /// <param name="variation">The variation.</param> public void BeginVariation(TestItemData variation) { this.testItemStack.Push(variation); this.writer.WriteStartElement("Variation"); this.writer.WriteAttributeString("Pri", XmlConvert.ToString(variation.Metadata.Priority)); this.writer.WriteAttributeString("Id", XmlConvert.ToString(variation.Metadata.Id)); this.writer.WriteAttributeString("Desc", variation.Metadata.Description); this.writer.WriteString("\r\n"); this.writer.Flush(); }
private void WriteResult(TestItemData testItem, TestResult result, ExceptionDetails exception) { if (exception != null) { this.WriteStatusText(LogLevel.Error, this.currentIndentLevel, this.ExceptionFormatter(exception)); } this.Unindent(); this.WriteStatusText(LogLevel.Info, this.currentIndentLevel, string.Format(CultureInfo.InvariantCulture, "{0} '{1}' {2}", this.GetItemTypeName(testItem), testItem.Metadata.Description, result.ToString())); }
/// <summary> /// Ends the variation. /// </summary> /// <param name="variation">The variation.</param> /// <param name="result">The result.</param> /// <param name="exception">The exception.</param> public void EndVariation(TestItemData variation, TestResult result, ExceptionDetails exception) { var currentVariation = this.testItemStack.Pop(); ExceptionUtilities.Assert(currentVariation == variation, "Invalid test case on stack."); this.WriteResult(result, exception); this.writer.WriteEndElement(); this.writer.WriteString("\r\n"); this.writer.Flush(); }
/// <summary> /// Begins the test case. /// </summary> /// <param name="testCase">The test case.</param> public void BeginTestCase(TestItemData testCase) { this.testItemStack.Push(testCase); var metadata = testCase.Metadata; this.writer.WriteStartElement("TestCase"); this.writer.WriteAttributeString("Name", metadata.Name); this.writer.WriteAttributeString("Desc", metadata.Description); this.writer.WriteString("\r\n"); this.writer.Flush(); }
private void WriteTestItemDataDurationResult(TestItemData testItem) { var currentTestCaseWithTime = this.testItemTimeStack.Pop(); ExceptionUtilities.Assert(testItem == currentTestCaseWithTime.Key, "Invalid test case on stack."); var elapsed = this.GetCurrentTime() - currentTestCaseWithTime.Value; bool writeOutInitTerminateTime = false; // Adding information on whether the information recorded is for a Variation - V, TestCase - TC, or TestModule - TM string type = "V"; if (testItem.IsTestCase) { type = "TC"; writeOutInitTerminateTime = true; } else if (testItem is TestModuleData) { type = "TM"; writeOutInitTerminateTime = true; } // Getting TestCase Name, escaping the commas as it makes it more difficult // to import into excel var nestedName = this.GetNestedTestName(currentTestCaseWithTime.Key).Replace(',', ';'); this.writer.WriteLine("{0}, {1}, {2}", type, nestedName, elapsed.TotalMilliseconds); // Add to running total of time if there is a parent if (testItem.Parent != null) { this.testItemRunningTotalLookup[testItem.Parent] = this.testItemRunningTotalLookup[testItem.Parent] + elapsed.TotalMilliseconds; } if (writeOutInitTerminateTime) { var runningTotal = this.testItemRunningTotalLookup[testItem]; var startupTearDownTime = elapsed.TotalMilliseconds - runningTotal; // Write out the time that occurs between running the parent test and the child tests this.writer.WriteLine("{0}, {1}, {2}", type + "_I-T", nestedName, startupTearDownTime); } // Remove this item as its unneeded now this.testItemRunningTotalLookup.Remove(testItem); this.writer.Flush(); }
private bool ShouldRun(TestItemData testItemData) { if (this.executionThreadAborted) { return(false); } if (testItemData.IsVariation) { return(this.scheduledVariations.ContainsKey(testItemData)); } else { return(testItemData.Children.Any(i => this.ShouldRun(i))); } }
private string GetItemTypeName(TestItemData testItem) { string itemKind = string.Empty; if (testItem.IsVariation) { itemKind = "Variation"; } else if (testItem.IsTestCase) { itemKind = "Test Case"; } else if (testItem is TestModuleData) { itemKind = "Test Module"; } return(itemKind); }
private static string GetFullPath(TestItemData item) { // module isn't represented in the path if (item.Parent == null) { return(string.Empty); } string name = item.Metadata.Name; string parentName = GetFullPath(item.Parent); if (!string.IsNullOrEmpty(parentName)) { name = parentName + '/' + name; } return(name); }
private string GetNestedTestName(TestItemData itemData) { string name = null; var currentItemData = itemData; while (currentItemData != null) { if (name == null) { name = currentItemData.Metadata.Name; } else { name = currentItemData.Metadata.Name + "." + name; } currentItemData = currentItemData.Parent; } return(name); }
private void IncrementResultCounter(TestItemData testItemData, TestResult result) { int priority = testItemData.Metadata.Priority; RunStatistics statistics; if (!this.statisticsByPriority.TryGetValue(priority, out statistics)) { this.statisticsByPriority[priority] = statistics = new RunStatistics(); } switch (result) { case TestResult.Timeout: ++statistics.Timeouts; ++this.globalStatistics.Timeouts; break; case TestResult.Skipped: ++statistics.Skipped; ++this.globalStatistics.Skipped; break; case TestResult.Failed: ++statistics.Failures; ++this.globalStatistics.Failures; break; case TestResult.Passed: ++statistics.Passed; ++this.globalStatistics.Passed; break; case TestResult.Warning: ++statistics.Warnings; ++this.globalStatistics.Warnings; break; } }
private void LogBeginTestItem(TestItemData itemData) { var testModuleData = itemData as TestModuleData; if (testModuleData != null) { this.currentLogWriter.BeginTestModule(testModuleData); return; } if (itemData.IsTestCase) { this.currentLogWriter.BeginTestCase(itemData); return; } if (itemData.IsVariation) { this.currentLogWriter.BeginVariation(itemData); return; } }
/// <summary> /// Ends the test case. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="result">The result.</param> /// <param name="exception">The exception.</param> public void EndTestCase(TestItemData testCase, TestResult result, ExceptionDetails exception) { var currentTestCase = this.testItemStack.Pop(); ExceptionUtilities.Assert(testCase == currentTestCase, "Invalid test case on stack."); // Working around Aruba LTM driver bug with nested test cases. When we write an // end element for TestCase, the driver thinks we are now writing data about the // TestModule. This assumption is invalid because we could be processing nested TestCases. // If we have violated this assumption then writing the Result element will cause the // driver to think that this is the result for the TestModule and therefore stop processing // the log file. This workaround gets around most cases except for when a failure/warning/skip // occurs in TestCase.Terminate, or when a skip occurs in TestCase.Init. if (result != TestResult.Passed) { this.WriteResult(result, exception); } this.writer.WriteEndElement(); this.writer.WriteString("\r\n"); this.writer.Flush(); }
private void ExecuteNextChild() { do { this.currentContext.CurrentChildIndex++; }while (this.currentContext.CurrentChildIndex < this.currentContext.TestItem.Children.Count && !this.ShouldRun(this.currentContext.TestItemData.Children[this.currentContext.CurrentChildIndex])); if (this.currentContext.CurrentChildIndex < this.currentContext.TestItem.Children.Count) { var testItem = this.currentContext.TestItem.Children[this.currentContext.CurrentChildIndex]; var testItemData = this.currentContext.TestItemData.Children[this.currentContext.CurrentChildIndex]; ExceptionUtilities.Assert(TestItemData.Matches(testItemData, testItem), "TestItemData and TestItem hierarchies should match exactly."); this.BeginExecution( testItem, testItemData); } else { this.EnterState(CurrentState.Terminating); } }
private void BeginExecution(TestItem testItem, TestItemData itemData) { if (this.currentContext != null) { this.executionContextStack.Push(this.currentContext); } this.currentContext = new ExecutionContext() { TestItem = testItem, TestItemData = itemData, CurrentChildIndex = -1, CurrentState = CurrentState.Initializing, CurrentResult = TestResult.InProgress, }; this.ReportItemStarting(TestResult.InProgress); this.LogBeginTestItem(itemData); var callback = this.CreateCallback(); this.RunOnExecutionThread(() => testItem.InitAsync(callback)); }
/// <summary> /// Ends the variation. /// </summary> /// <param name="variation">The variation.</param> /// <param name="result">The result.</param> /// <param name="exception">The exception.</param> public void EndVariation(TestItemData variation, TestResult result, ExceptionDetails exception) { this.ForAll(i => i.EndVariation(variation, result, exception)); }
/// <summary> /// Ends the variation. /// </summary> /// <param name="variation">The variation.</param> /// <param name="result">The result.</param> /// <param name="exception">The exception.</param> public void EndVariation(TestItemData variation, TestResult result, ExceptionDetails exception) { }
/// <summary> /// Begins the variation. /// </summary> /// <param name="variation">The variation.</param> public void BeginVariation(TestItemData variation) { }
/// <summary> /// Begins the variation. /// </summary> /// <param name="variation">The variation.</param> public void BeginVariation(TestItemData variation) { this.ForAll(i => i.BeginVariation(variation)); }
private static string GetFullPath(TestItemData item) { // module isn't represented in the path if (item.Parent == null) { return string.Empty; } string name = item.Metadata.Name; string parentName = GetFullPath(item.Parent); if (!string.IsNullOrEmpty(parentName)) { name = parentName + '/' + name; } return name; }
/// <summary> /// Initializes a new instance of the TestItemStatusChangedEventArgs class. /// </summary> /// <param name="testItemData">The test item.</param> /// <param name="result">The result.</param> public TestItemStatusChangedEventArgs(TestItemData testItemData, TestResult result) { this.TestItemData = testItemData; this.TestResult = result; }
/// <summary> /// Ends the test case. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="result">The result.</param> /// <param name="exception">The exception.</param> public void EndTestCase(TestItemData testCase, TestResult result, ExceptionDetails exception) { }
private string GetNestedTestName(TestItemData itemData) { string name = null; var currentItemData = itemData; while (currentItemData != null) { if (name == null) { name = currentItemData.Metadata.Name; } else { name = currentItemData.Metadata.Name + "." + name; } currentItemData = currentItemData.Parent; } return name; }
/// <summary> /// Begins the test case. /// </summary> /// <param name="testCase">The test case.</param> public void BeginTestCase(TestItemData testCase) { this.testItemRunningTotalLookup.Add(testCase, 0); this.testItemTimeStack.Push(new KeyValuePair <TestItemData, DateTimeOffset>(testCase, this.GetCurrentTime())); }
/// <summary> /// Begins the variation. /// </summary> /// <param name="variation">The variation.</param> public void BeginVariation(TestItemData variation) { this.testItemTimeStack.Push(new KeyValuePair <TestItemData, DateTimeOffset>(variation, this.GetCurrentTime())); }
/// <summary> /// Ends the test case. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="result">The result.</param> /// <param name="exception">The exception.</param> public void EndTestCase(TestItemData testCase, TestResult result, ExceptionDetails exception) { this.WriteResult(testCase, result, exception); }
/// <summary> /// Begins the test case. /// </summary> /// <param name="testCase">The test case.</param> public void BeginTestCase(TestItemData testCase) { }
/// <summary> /// Begins the variation. /// </summary> /// <param name="variation">The variation.</param> public void BeginVariation(TestItemData variation) { this.WriteBegin(variation); }
private void WriteBegin(TestItemData testItem) { this.WriteStatusText(LogLevel.Info, this.currentIndentLevel, string.Format(CultureInfo.InvariantCulture, "{0} '{1}' Starting", this.GetItemTypeName(testItem), testItem.Metadata.Description)); this.Indent(); }
/// <summary> /// Determines whether the specified <see cref="TestItemData"/> instance /// matches the specified <see cref="TestItem"/>. Matching, in this case, /// means that both objects have the same metadata, and all of their /// parents have the same metadata. /// </summary> /// <param name="testItemData">The <see cref="TestItemData"/> to compare with the <see cref="TestItem"/>.</param> /// <param name="other">The <see cref="TestItem"/> to consider.</param> /// <returns> /// true if this <see cref="TestItemData"/> matches the specified /// <see cref="TestItem"/>. Otherwise, false. /// </returns> public static bool Matches(TestItemData testItemData, TestItem other) { if (testItemData == null && other == null) { return true; } if ((testItemData == null) != (other == null)) { return false; } if (testItemData.TestItemType != other.GetType()) { return false; } if (!testItemData.Metadata.Equals(other.Metadata)) { return false; } if (object.ReferenceEquals(testItemData.Parent, null) != (other.Parent == null)) { return false; } if (testItemData.Parent != null) { return Matches(testItemData.Parent, other.Parent); } return true; }
/// <summary> /// Begins the test case. /// </summary> /// <param name="testCase">The test case.</param> public void BeginTestCase(TestItemData testCase) { this.testItemRunningTotalLookup.Add(testCase, 0); this.testItemTimeStack.Push(new KeyValuePair<TestItemData, DateTimeOffset>(testCase, this.GetCurrentTime())); }
/// <summary> /// Ends the variation. /// </summary> /// <param name="variation">The variation.</param> /// <param name="result">The result.</param> /// <param name="exception">The exception.</param> public void EndVariation(TestItemData variation, TestResult result, ExceptionDetails exception) { this.WriteResult(variation, result, exception); }
/// <summary> /// Determines whether the specified <see cref="TestItemData"/> is equal to this instance. /// </summary> /// <param name="other">The <see cref="TestItemData"/> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="TestItemData"/> is equal to this instance; otherwise, <c>false</c>. /// </returns> public bool Equals(TestItemData other) { if (object.ReferenceEquals(other, null)) { return false; } if (this.GetType() != other.GetType()) { return false; } if (object.ReferenceEquals(this.Parent, null) != object.ReferenceEquals(other.Parent, null)) { return false; } if (object.ReferenceEquals(this.Parent, null)) { return this.Metadata.Equals(other.Metadata); } return this.Metadata.Equals(other.Metadata) && this.Parent.Equals(other.Parent); }
/// <summary> /// Initializes a new instance of the <see cref="TestItemData"/> class. /// </summary> /// <param name="testItem">The test item whose data is exposed.</param> /// <param name="parent">The parent of this <see cref="TestItemData"/>, if it exists.</param> public TestItemData(TestItem testItem, TestItemData parent) : this(testItem) { this.Parent = parent; }
/// <summary> /// Begins the test case. /// </summary> /// <param name="testCase">The test case.</param> public void BeginTestCase(TestItemData testCase) { this.WriteBegin(testCase); }
private string GetItemTypeName(TestItemData testItem) { string itemKind = string.Empty; if (testItem.IsVariation) { itemKind = "Variation"; } else if (testItem.IsTestCase) { itemKind = "Test Case"; } else if (testItem is TestModuleData) { itemKind = "Test Module"; } return itemKind; }
/// <summary> /// Begins the test case. /// </summary> /// <param name="testCase">The test case.</param> public void BeginTestCase(TestItemData testCase) { this.ForAll(i => i.BeginTestCase(testCase)); }
/// <summary> /// Ends the test case. /// </summary> /// <param name="testCase">The test case.</param> /// <param name="result">The result.</param> /// <param name="exception">The exception.</param> public void EndTestCase(TestItemData testCase, TestResult result, ExceptionDetails exception) { this.ForAll(i => i.EndTestCase(testCase, result, exception)); }
/// <summary> /// Begins the variation. /// </summary> /// <param name="variation">The variation.</param> public void BeginVariation(TestItemData variation) { this.testItemTimeStack.Push(new KeyValuePair<TestItemData, DateTimeOffset>(variation, this.GetCurrentTime())); }