TFS build problem: missing assembly in test output folder - tfs

I am trying to integrate unit test cases with a TFS build in our new solution. I've include the following configuration line in my TFSBuild.proj
<ItemGroup>
<TestContainer Include="$(OutDir)\%2aTest.dll" />
</ItemGroup>
Which I think is the correct configuration since I only have 1 test project. However, when I do this, some dll is missing in the output folder of the test case, hence failing most of my test case. Has anyone run into this problem before?
Thanks!

Either reference the project for the missing file from the test project, or add the missing file as a deployment item in your .testrunconfig file.
MSTest only copies the libraries it thinks it needs to to the test folder.

Related

TFS Build using vstest.console.exe.config instead of app.config

For some time we had TFS2017 run our unit test (xUnit) in the build proces. Every test project has it own app.config file declaring some appSettings.
Our code is looking at those app settings like ConfigurationManager.AppSettings["someSetting"]
Recently, some developers upgraded from VS2015 to VS2017 (not sure if it is related), our test started to fail.
Turns out that the the appSettings where loaded from vstest.console.exe.configinstead of the app.config file included in the test project.
While we where able to add our settings to vstest.console.exe.config this is not our preferred solution, we would like to have the test using the app.config file again.
Any ideas on how to accomplish this? I have no idea what changed in the first place.
Make sure WorkingFolder is not changed. It should be relative to the folder containing the test.dll.
Also, you can try the <exec> task in MSBuild to run the console runner.
When running multiple assemblies, you can specify the configuration file for each assembly using ItemGroup metadata. The <xunit> task looks for metadata named ConfigFile on each item in your item group. Configuration files are ignored when AppDomains is set to false.

NUnit tests with TFS 2013

I'm trying to get TFS to run my unit tests.
The name of the project assembly is Users.SystemTests.dll. It's located in ~/source/Users.SystemTests/bin/debug. The solution file is located in ~/source/Users.sln.
I've included the Nunit.VisualStudio.TestAdapter nuget package the in test assembly project.
The results of the build shows that the tests don't run.
What am I missing? They run fine locally via the Resharper test runner and I can also use nunit-console-x86.exe to run them.
Does this have something to do with the fact that I'm building a solution file? Maybe it's the output location being "AsConfigured?"
Ok, so I tracked this down on my own. It was twofold. The first problem was the the TestAdapter was not being output to the bin directory. The other piece was the Output Location. Setting copy local and then Output Location SingleFolder fixed the issue.
I do believe this is a bug in the tfs build. It works when you use SingleFolder or PerProject, but not AsConfigured. In the latter case the test runner don't find the testassemblies, and this is the same for both NUnit and MSTest, so it is not adapter specific.
The diagnostics log says:
Run VS Test Runner00:00:00
There were no matches for the search pattern C:\a\bin\**\*test*.dll
There were no matches for the search pattern C:\a\bin\**\*test*.appx

Chutzpah running Jasmine in TFS 2012 can't find referenced file under test

I am using Chutzpah to run our Jasmine tests.
I have added the Chutzpah dlls to the solution and updated the build to run *.js tests.
The project structure is as follows:
MyApp.Web
Scripts
App
Home
DateControl.js
MyApp.Web.Tests
Scripts
Jasmine
lib
Chutzpah (dlls)
Spec
App
Home
DateControlSpecs.js
The Jasmine test file uses a reference tag to reference the file to be tested
/// <reference path="../../../../../../App.web/scripts/app/home/datecontrol.js" />
The Jasmine tests are run however I get the following error:
ReferenceError: Can't find variable: dateControl in file
dateControl is the object under test.
If I copy the code to be tested into the Jasmine test file then the tests pass.
The jasmine tests with the reference tag pass using the Chutzpah Test Adapter in Test Explorer in Visual Studio 2013.
I have no idea why this is not working.
Update
#jessehouwing's answer pointed out the route of the issue for me.
The build folder on the build server has the following structure
bin
_PublishedWebsites
src
The jasmine test scripts and libraries are copied to bin whereas the script files under test are copied to both the src directory and the _publishedwebsite directory.
I am looking for an easy to manage solution so that any future devs do not need to know they need to link any new scripts into the test project.
Solution I can live with for now
For both the jasmine test files and the files under test I added "Always copy" in properties as per the Chutzpah documentation. I didn't realise that the files under test were actually being copied to the builds bin folder along with the jasmine test files.
So on the build server I ended up with the following struacture
bin
scripts
app
* application js files
specs
* jasmine test files
In my jasmine test file I add two references:
The first to the Visual Studio directory sturcture of the file to be tested
The second to the build bin folder structure
Hack 1
I can get it to work by adding another reference to my jasmine test file which uses the structure of the build directory and not the solution directory structure but again this is open to error as the path may be typed in incorrectly.
The second reference below will allow the tests to run in both VS Test Explorer and TFS Build
/// <reference path="../../../../../../App.Web/scripts/app/home/datecontrol.js" />
/// <reference path="../../../../../_PublishedWebsites\App.Web/scripts/app/home/datecontrol.js" />
Hack 2
By adding an xcopy command to the post-build build event of the project I can copy the files to be tested into the same location as the jasmine test files.
This is most likely caused by the fact that Team Build separates the Sources and Binaries folders and enforces a different output structure in the Binaries folder as well. This means your files are not in the place you expect them to be.
To ensure the test runner can always find your references you must use the "Add as Link" option in Visual Studio and set their build action to "Copy Always" so that they're copied to the test directory upon test execution.
Plus, you might need to enable "Deployment" in the Test configuration in your Build Definition, as outlined here.

Jasmine in a separate test project

Is it practical/possible to separate jasmine tests into a separate visual studio project?
I am just getting started with angular, and am trying to write my tests before I start on the actual angular implementation. I will be writing my project in Visual Studio 2012 with the Chutzpah test runner, see this video. Currently, I am trying to figure out how to organize my folder structure. I know about angular-seed and yeoman, but those are ill suited to starting a .net project.
I am assuming that since unit tests in Visual Studio are usually separated into a separate test project, by convention, the jasmine tests should, too.
However, for java script, there are no project dlls to reference, so separating the tests out into a different project would require a lot of copy and pasting, I think.
You can do this with no copy/pasting. In your Jasmine tests you can add a /// <reference comment which posts to your source files (or the directory containing them). For example given this sturcture
/ProjectA /scripts
code1.js
code2.js
/TestProjectB test1.js
You can add this line at the top of your test1.js file to reference all your code files:
/// <reference path="../scripts" />
Traditionally, I've always kept unit tests in separate assemblies.
I've read both sides of the argument and prefer not to ship code that isn't production code, or to have additional deployment steps to remove tests from production code.
In order to reference javascript in my Web.Client.Tests assembly, for example, I use a post-build event to copy the files into the test project. For this I use robocopy - it looks something like this:
robocopy "$(ProjectDir)app" "$(SolutionDir)Tests\Presentation\Web.Client.Tests\app" /E /COPY:D /IS
robocopy "$(ProjectDir)Scripts" "$(SolutionDir)Tests\Presentation\Web.Client.Tests\Scripts" /E /COPY:D /IS
if errorlevel 1 GOTO :eof
The main con with this approach is that you have to build the project each time, like you'd have to with your C# code, to update the test project before running the tests.
Think you should use default folder structure as recomended by jasmine
here is a link showing default structure of jasmine

TFS Build Error While Invoking custom build file via TFS Build definition

I use TFS 2010, VS 2010.
I wrote a custom msbuild proj file which I use locally to build my solution. I use MSBUILD.exe TFSBuild.proj and it does everything in my local machine. (I have a taregt called 'DoMyBuild' which kicks off the build and does everything.)
I have used this in the DefaultTargets attribute as below:
<Project DefaultTargets="DoMyBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
I am trying hard to configure this to use my build server with a build definition. In the build definition, under Process - I configured 'Upgrade Template' and in the build process paramters, have given the path to this TFSBuild.Proj file.
Ideally. TFS should start 'DoMyBuild' target as I read. But it gives a error looking for 'EndToEndIteration' not defined. So, I believe it is still doing a DesktopBuild which I dont want. I want to use my custom target to kick start. Is this possible ?
Any help is very much appreciated.
Thanks, Mani
You problem is discussed here.
Make sure you have at least an EndToEndIteration target defined in your MSBuild project.
<Target Name="EndToEndIteration"
Condition=" '$(IsDesktopBuild)'!='true' "
DependsOnTargets="$(EndToEndIterationDependsOn)" />

Resources