/// <summary> /// Converts the test result into XML that is consumed by the test runners. /// </summary> /// <param name="parentNode">The parent node.</param> /// <returns>The newly created XML node.</returns> public override XmlNode ToXml(XmlNode parentNode) { XmlNode assemblyNode = XmlUtility.AddElement(parentNode, "assembly"); XmlUtility.AddAttribute(assemblyNode, "name", Filename); XmlUtility.AddAttribute(assemblyNode, "run-date", DateTime.Now.ToString("yyyy-MM-dd")); XmlUtility.AddAttribute(assemblyNode, "run-time", DateTime.Now.ToString("HH:mm:ss")); if (ConfigFilename != null) { XmlUtility.AddAttribute(assemblyNode, "configFile", ConfigFilename); } foreach (ClassResult child in Results) { child.ToXml(assemblyNode); // Must call so that values get computed PassCount += child.PassCount; FailCount += child.FailCount; SkipCount += child.SkipCount; ExecutionTime += child.ExecutionTime; } AddTime(assemblyNode); XmlUtility.AddAttribute(assemblyNode, "total", PassCount + FailCount + SkipCount); XmlUtility.AddAttribute(assemblyNode, "passed", PassCount); XmlUtility.AddAttribute(assemblyNode, "failed", FailCount); XmlUtility.AddAttribute(assemblyNode, "skipped", SkipCount); XmlUtility.AddAttribute(assemblyNode, "environment", String.Format("{0}-bit .NET {1}", IntPtr.Size * 8, Environment.Version)); XmlUtility.AddAttribute(assemblyNode, "test-framework", String.Format("xUnit.net {0}", Assembly.GetExecutingAssembly().GetName().Version)); return(assemblyNode); }
/// <summary> /// Converts the test result into XML that is consumed by the test runners. /// </summary> /// <param name="parentNode">The parent node.</param> /// <returns>The newly created XML node.</returns> public override XmlNode ToXml(XmlNode parentNode) { XmlNode testNode = base.ToXml(parentNode); XmlUtility.AddAttribute(testNode, "result", "Pass"); AddTime(testNode); return(testNode); }
/// <summary> /// Converts the test result into XML that is consumed by the test runners. /// </summary> /// <param name="parentNode">The parent node.</param> /// <returns>The newly created XML node.</returns> public override XmlNode ToXml(XmlNode parentNode) { XmlNode testNode = base.ToXml(parentNode); XmlUtility.AddAttribute(testNode, "result", "Skip"); XmlNode reasonNode = XmlUtility.AddElement(testNode, "reason"); XmlNode messageNode = XmlUtility.AddElement(reasonNode, "message"); messageNode.InnerText = Reason; return(testNode); }
/// <inheritdoc/> public virtual XmlNode ToStartXml() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<dummy/>"); XmlNode testNode = XmlUtility.AddElement(doc.ChildNodes[0], "start"); XmlUtility.AddAttribute(testNode, "name", DisplayName); XmlUtility.AddAttribute(testNode, "type", TypeName); XmlUtility.AddAttribute(testNode, "method", MethodName); return(testNode); }
/// <summary> /// Converts the test result into XML that is consumed by the test runners. /// </summary> /// <param name="parentNode">The parent node.</param> /// <returns>The newly created XML node.</returns> public override XmlNode ToXml(XmlNode parentNode) { failCount = 0; passCount = 0; skipCount = 0; ExecutionTime = 0.0; XmlNode classNode = XmlUtility.AddElement(parentNode, "class"); if (Message != null) { failCount += 1; XmlNode failureNode = XmlUtility.AddElement(classNode, "failure"); XmlUtility.AddAttribute(failureNode, "exception-type", ExceptionType); XmlNode messageNode = XmlUtility.AddElement(failureNode, "message"); messageNode.InnerText = Message; XmlNode stackTraceNode = XmlUtility.AddElement(failureNode, "stack-trace"); stackTraceNode.InnerText = StackTrace; } foreach (ITestResult testResult in Results) { testResult.ToXml(classNode); if (testResult is PassedResult) { passCount++; } else if (testResult is FailedResult) { failCount++; } else if (testResult is SkipResult) { skipCount++; } ExecutionTime += testResult.ExecutionTime; } AddTime(classNode); XmlUtility.AddAttribute(classNode, "name", FullyQualifiedName); XmlUtility.AddAttribute(classNode, "total", classNode.ChildNodes.Count); XmlUtility.AddAttribute(classNode, "passed", passCount); XmlUtility.AddAttribute(classNode, "failed", failCount); XmlUtility.AddAttribute(classNode, "skipped", skipCount); return(classNode); }
void AddTraits(XmlNode testNode) { if (Traits.Count > 0) { XmlNode propertiesNode = XmlUtility.AddElement(testNode, "traits"); Traits.ForEach((name, value) => { XmlNode propertyNode = XmlUtility.AddElement(propertiesNode, "trait"); XmlUtility.AddAttribute(propertyNode, "name", name); XmlUtility.AddAttribute(propertyNode, "value", value); }); } }
/// <summary> /// Converts the test result into XML that is consumed by the test runners. /// </summary> /// <param name="parentNode">The parent node.</param> /// <returns>The newly created XML node.</returns> public override XmlNode ToXml(XmlNode parentNode) { XmlNode testNode = XmlUtility.AddElement(parentNode, "test"); XmlUtility.AddAttribute(testNode, "name", DisplayName); XmlUtility.AddAttribute(testNode, "type", TypeName); XmlUtility.AddAttribute(testNode, "method", MethodName); AddTraits(testNode); if (!String.IsNullOrEmpty(Output)) { XmlNode node = XmlUtility.AddElement(testNode, "output"); node.InnerText = Output; } return(testNode); }
/// <summary> /// Converts the test result into XML that is consumed by the test runners. /// </summary> /// <param name="parentNode">The parent node.</param> /// <returns>The newly created XML node.</returns> public override XmlNode ToXml(XmlNode parentNode) { XmlNode testNode = base.ToXml(parentNode); XmlUtility.AddAttribute(testNode, "result", "Fail"); AddTime(testNode); XmlNode failureNode = XmlUtility.AddElement(testNode, "failure"); XmlUtility.AddAttribute(failureNode, "exception-type", ExceptionType); XmlNode messageNode = XmlUtility.AddElement(failureNode, "message"); messageNode.InnerText = Message; if (!string.IsNullOrEmpty(StackTrace)) { XmlNode stackTraceNode = XmlUtility.AddElement(failureNode, "stack-trace"); stackTraceNode.InnerText = StackTrace; } return(testNode); }
/// <summary> /// Adds the test execution time to the XML node. /// </summary> /// <param name="testNode">The XML node.</param> protected void AddTime(XmlNode testNode) { XmlUtility.AddAttribute(testNode, "time", ExecutionTime.ToString("0.000", CultureInfo.InvariantCulture)); }
public EnumerateTests(Executor executor, object _handler) { ExecutorCallback handler = ExecutorCallback.Wrap(_handler); XmlDocument doc = new XmlDocument(); doc.LoadXml("<dummy/>"); XmlNode assemblyNode = XmlUtility.AddElement(doc.ChildNodes[0], "assembly"); XmlUtility.AddAttribute(assemblyNode, "name", executor.assemblyFilename); foreach (Type type in executor.assembly.GetExportedTypes()) { ITestClassCommand testClassCommand = TestClassCommandFactory.Make(type); if (testClassCommand != null) { string typeName = type.FullName; XmlNode classNode = XmlUtility.AddElement(assemblyNode, "class"); XmlUtility.AddAttribute(classNode, "name", typeName); foreach (IMethodInfo method in testClassCommand.EnumerateTestMethods()) { string methodName = method.Name; string displayName = null; foreach (IAttributeInfo attr in method.GetCustomAttributes(typeof(FactAttribute))) { displayName = attr.GetPropertyValue <string>("Name"); } XmlNode methodNode = XmlUtility.AddElement(classNode, "method"); XmlUtility.AddAttribute(methodNode, "name", displayName ?? typeName + "." + methodName); XmlUtility.AddAttribute(methodNode, "type", typeName); XmlUtility.AddAttribute(methodNode, "method", methodName); string skipReason = MethodUtility.GetSkipReason(method); if (skipReason != null) { XmlUtility.AddAttribute(methodNode, "skip", skipReason); } var traits = MethodUtility.GetTraits(method); if (traits.Count > 0) { XmlNode traitsNode = XmlUtility.AddElement(methodNode, "traits"); traits.ForEach((name, value) => { XmlNode traitNode = XmlUtility.AddElement(traitsNode, "trait"); XmlUtility.AddAttribute(traitNode, "name", name); XmlUtility.AddAttribute(traitNode, "value", value); }); } } } } handler.Notify(assemblyNode.OuterXml); }