Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here you have a way to get the Assembly name:</p> <pre><code> foreach (ITestCaseResult testCaseResult in failures) { string testName = testCaseResult.TestCaseTitle; ITmiTestImplementation testImplementation = testCaseResult.Implementation as ITmiTestImplementation; string assembly = testImplementation.Storage; } </code></pre> <p>Unfortunately, <strong>ITestCaseResult</strong> and <strong>ITmiTestImplementation</strong> don’t seem to contain the namespace of the test case. </p> <p>Check the last response in <a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/48effc10-4b42-4f70-825d-dbaa6d1bb06b/using-the-tfs-apis-to-find-the-name-assembly-and-namespace-of-a-failed-unit-test-after-a-build?forum=tfsbuild" rel="nofollow">this link</a>, that might help. Good Luck!</p> <p><strong>EDIT</strong>: This is based on <strong>Charles Crain</strong>'s answer, but getting the class name without having to download to file:</p> <pre><code> var className = GetTestClassName(testResult.Attachments); </code></pre> <p>And the method itself:</p> <pre><code> private static string GetTestClassName(IAttachmentCollection attachmentCol) { if (attachmentCol == null || attachmentCol.Count == 0) { return string.Empty; } var attachment = attachmentCol.First(att =&gt; att.AttachmentType == "TmiTestResultDetail"); var content = new byte[attachment.Length]; attachment.DownloadToArray(content, 0); var strContent = Encoding.UTF8.GetString(content); var reader = XmlReader.Create(new StringReader(RemoveTroublesomeCharacters(strContent))); var root = XElement.Load(reader); var nameTable = reader.NameTable; if (nameTable != null) { var namespaceManager = new XmlNamespaceManager(nameTable); namespaceManager.AddNamespace("ns", "http://microsoft.com/schemas/VisualStudio/TeamTest/2010"); var classNameAtt = root.XPathSelectElement("./ns:TestDefinitions/ns:UnitTest[1]/ns:TestMethod[1]", namespaceManager).Attribute("className"); if (classNameAtt != null) return classNameAtt.Value.Split(',')[1].Trim(); } return string.Empty; } internal static string RemoveTroublesomeCharacters(string inString) { if (inString == null) return null; var newString = new StringBuilder(); foreach (var ch in inString) { // remove any characters outside the valid UTF-8 range as well as all control characters // except tabs and new lines if ((ch &lt; 0x00FD &amp;&amp; ch &gt; 0x001F) || ch == '\t' || ch == '\n' || ch == '\r') { newString.Append(ch); } } return newString.ToString(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload