9

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

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
SteckDEV
  • 489
  • 4
  • 13

4 Answers4

9

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;
Márcio Azevedo
  • 123
  • 1
  • 4
  • 8
  • I had integrationTests I wanted to ignore, so I used `..\src\*.test\bin\*\*.test.dll` – NGaida Mar 23 '15 at 21:09
  • 1
    I want to search in subdirs also, not just directly under src. `..\src\**\*test*.dll` does that, but finds every test twice, presumably because it finds both `bin\Debug\test.dll` and `obj\Debug\test.dll`. I've tried `..\src\**\bin\*\*test*.dll`, but that finds nothing. Haven't found a complete solution short of hacking the XAML – Jonathan Apr 13 '15 at 11:00
2

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;
Richard II
  • 853
  • 9
  • 31
  • This doesn't work if you have multiple build configuration, for example build and debug. Since you have to specify the exact path, it will run the debug tests for both builds. – Gabriel G. Roy Jul 15 '14 at 18:02
  • @Deli, could you setup two different build definitions, one for your release build, and another for the debug build? Then each build definition should specify its own set of test binaries. That's sounds annoying, but most workarounds are. – Richard II Jul 17 '14 at 18:22
  • Yeah, it should work, only it takes a bit more time since the code needs to be checked-out twice. – Gabriel G. Roy Jul 18 '14 at 13:21
  • 1
    This `..\src\**\*test.dll` works for me, with no need to specify the projects (if it suites your needs). – Yaakov Shoham Mar 15 '15 at 07:24
  • I have "AsConfigured" setting on for X64 platform that places the binaries into `src\x64\Release\\` (and it used to place them into `bin\x64\Release\\` without that switch). So, I ended up using `..\..\..\src\**\*test*.dll` as my "Test Sources spec". – Vladimir Shutow Oct 24 '17 at 16:56
1

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.

SteckDEV
  • 489
  • 4
  • 13
0

Another solution is to do the reverse.

Leave all of the files in the root so that all of the built in functionality works. There is more than just test execution in there. What about static code analysis, impact analysis..among others. You would have to do something custom for them all.

Instead use a pre-drop powershell script to create your Install arrangement from the root files.

If it is an application then you can use the _ApplicationFolder Nuget package to create an _PublishApplications folder same as you get for web applications.