Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AsConfigured and still be able to get UnitTest results in TFS

So I am running into an issue when I go to build my projects using tfs build controller using the Output location "AsConfigred" it will not detect my unit tests. Let me give a little info on my setup.

TFS 2013 Update 2, Default Process Template

Here is a few screenshots that can hopefully help fill in what I can't in typing. I am copying my build out to a file share on our network so that we can use other utilities use the output. I don't want to use "PerProject" or "SingleFolder" because they mess up the file structure we have configured (These both will run the tests). So i have the files copy to folder names "SingleOutputFolder" which is a child of the DropLocation. I would like to be able to run from the drop folder or run from the bin folder for each of my tests (I don't care which). However it doesn't seem to detect/run ANY of the tests. Any help would be greatly appreciated. Please let me know if you need any additional information.

I have tried using ***test*.dll, Install\SingleFolderOutput**.test.dll, and $(TF_BUILD_DROPLOCATION)\Install\SingleFolderOutput*test*.dll

But I am not sure what variables are available and understand where the scope of its execution is.

enter image description here

enter image description here

like image 668
SteckDEV Avatar asked Jun 13 '14 14:06

SteckDEV


People also ask

How do you manage test cases in TFS?

Additionally, TFS test case management integration allows teams to easily track the coverage of requirements, test results and bugs linked to TFS. To configure the TFS test management integration for TestRail, simply select Administration > Integration in TestRail and configure the TFS access details.

Can we write test cases in TFS?

TFS creates a test ID each time you add a new test case to a test suite. This ID is required when mapping TFS test cases to test methods. To create TFS test suites and add test cases: Run MTM and connect it to the team project from TFS where your project resides.

Can I export test results from Azure DevOps?

Yes. See Copy test cases. For Azure DevOps Server 2020 and later versions, you can copy test cases from within a project or another project to a test suite, or you can use the Grid view to copy and paste test cases from one suite to another. Optionally, you can bulk import and export test cases.


3 Answers

Given that you're using Build Output location set to AsConfigured you have to change the default values of the Test sources spec setting to allow build to find the test libraries in the bin folders. Here's an example.

If the full path to the unit test libraries is:

E:\Builds\7\<TFS Team Project>\<Build Definition>\src\<Unit Test Project>\bin\Release\*test*.dll

use

..\src\*UnitTest*\bin\*\*test*.dll;
like image 159
Márcio Azevedo Avatar answered Oct 14 '22 15:10

Márcio Azevedo


This question was asked on MSDN forums here.

MSDN Forums Suggested Workaround

The suggested workaround in the accepted answer (as of 8 a.m. on June 20) is to specify the full path to the test projects' binary folders: For example:

C:\Builds\{agentId}\{teamProjectName}\{buildDefinitionName}\src\{solutionName}\{testProjectName}\bin*\Debug\*test*.dll*

which really should have been shown as

{agentWorkingFolder}\src\{relativePathToTestProjectBinariesFolder}\*test*.dll

However this approach is very brittle, for the following reasons:

  1. Any new test projects you add to the solution will not be executed until you add them to the build definition's list of test sources:
  2. It will break under any of the following circumstances:
    • the build definition is renamed
    • the working folder in build agent properties is modified
    • you have multiple build agents, and a different agent than the one you specified in {id} runs the build

Improved Workaround

My workaround mitigates the issues listed in #2 (can't do anything about #1).

In the path specified above, replace the initial part:

{agentWorkingFolder} 

with

..

so you have

..\src\{relativePathToTestProjectBinariesFolder}\*test*.dll

This works because the internal working directory is apparently the \binaries\ folder that is a sibling of the \src\ folder. Navigating up to the parent folder (whatever it is named, we don't care) and back in to \src\ before specifying the path to the test projects binaries does the trick.

Note: If you have multiple test projects, you add additional entries, separated with semicolons:

..\src\{relativePathToTestProjectONEBinariesFolder}\*test*.dll;..\src\{relativePathToTestProjectTWOBinariesFolder}\*test*.dll;..\src\{relativePathToTestProjectTHREEBinariesFolder}\*test*.dll;
like image 22
Richard II Avatar answered Oct 14 '22 14:10

Richard II


What I ended up doing was adding a post build event to copy all of the test.dll into the staging location folder in the specific build that is basically equivalent to where it would go on a SingleFolder build and do that on each test project.

if "$(TeamBuildOutDir)" == "" (
echo "Building Interactively not in TFS"
) else (
echo "Building in TFS"
xcopy "$(TargetDir)*.*" "$(TeamBuildBinaries)\" /Y /E /S
)

MSBUILD parameter in the build def that told it to basically drop in the folder that TFS looks for them.

/p:TeamBuildBinaries="$(TF_BUILD_BINARIESDIRECTORY)"

Kept the default Test assembly file specification:

**\*test*.dll

View this link for the information on the variable that I used and what relative path it exists at.

like image 23
SteckDEV Avatar answered Oct 14 '22 14:10

SteckDEV