6
votes

I'm wondering if it is possible to link Test Cases in TFS 2013 to xUnit tests. Currently it works fine for msTest tests but once I change the method attribute from 'TestMethod' to 'Fact' and rebuild the test no longer appears when I click the Associated Automation in the Test Case to link the two together.

Has anybody any experience or answers for this?

Thanks

1
Any luck with that? have same problem but using NUNIT - Paolo Vigori
I didn't find an answer to it but if you are on 2015 the functionality is coming shortly... Team Services User Voice - cjfarrelly

1 Answers

0
votes

It is possible with the TFS API. This PowerShell script show you how to do that (see: https://blogs.msdn.microsoft.com/gautamg/2012/01/01/how-to-associate-automation-programmatically/ for reference).

# Get TC
$tfsTpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TPC_URL)
$tms = $tfsTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
$tp = $tms.GetTeamProject($TP_NAME)
$tc = $tp.TestCases.Find($tcId)
# Compute Automation Guid
$sha1Crypto = new-object System.Security.Cryptography.SHA1CryptoServiceProvider
[Byte[]] $bytes = New-Object Byte[] 16
[Array]::Copy($sha1Crypto.ComputeHash([System.Text.Encoding]::Unicode.GetBytes($testName)), $bytes, $bytes.Length)
# Create association
$tc.Implementation = $tp.CreateTmiTestImplementation($testName, $AUTOMATION_TYPE, $AUTOMATION_STORAGE_NAME, $automationGuid)
$tc.Save()
$automationGuid = New-Object -TypeName Guid -ArgumentList @(,$bytes)

But you will not be able to associate the execution with the Test Case in TFS.

The test must be run with MSTest V1 to log results as a valid TRX to be published in TFS through TCM.exe. Even with vstest.console.exe and the TRX logger option the xml result is not understandable by TCM.exe.

For reference see: http://bugsareinthegaps.com/uploading-automated-test-results-to-mtm-made-easy/