5

So my situation is that I finally finished configuring TeamCity for CI. I got it to run my unit tests with some friendly help on SO.

However, many unit tests fail because there needs to be a config file alongside the unittests.dll once it's built and ready to run.

I've written a simple Command Line step with:

copy %system.teamcity.build.checkoutDir%\xx.configfile <destination>

The destination is the problem, I need it to be the Out directory teamcity creates.

TC creates SYSTEM_<machinename> <datetime>\OUT. An example:

C:\TeamCity\buildAgent\temp\buildTmp\SYSTEM_GIDEON 2015-07-02 16_51_09\Out

In there is my unittests.dll and I want to copy my config file there. What environment var or (anything else) can I use in the command line script?

The (1) Build Tests is a Step then I want to run the (2) Copy Config Step Then (3) Run Tests. After step (1) I have that xxx\xxx\Out directory and I need that directory from some variable.

I'm using Teamcity 9.0.2

Community
  • 1
  • 1
gideon
  • 19,329
  • 11
  • 72
  • 113

1 Answers1

2

Your problem is not to do with TeamCity I don't think, it's to do with the way that MSTest works. You need your .config file to be a DeploymentItem and have your tests deploy it to the directory that MSTest will run the tests in.

To be honest I'm surprised that you don't have this problem running locally, and it makes me think that you must be using some other test runner (like ReSharper) to run the tests if you have not seen this problem on your local machines.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • You're right, we had a problem sometime ago. We found a hack somewhere, inside the unittests.csproj we have an extra line ` .pdb; .xml; .dll.config ` which copies a class lib reference's reference's dll config into the bin, BUT this doesn't work with TC. I wonder if it's because I use MSBuild instead of a "Visual Studio Build" – gideon Jul 02 '15 at 12:22
  • It probably is. The solution is going to be to remove the hack in the csproj and get it working locally without that. The basic procedure to follow is to 1. ensure the file is placed in the build output directory (bin\debug\). If the file isn't there then DeploymentItem won't be able to find it. Usually this just means setting 'Copy to output directory' to 'Always' 2. Then use `DeploymentItem` to ensure that the file is deployed to the Out directory that the tests are run in. – Sam Holder Jul 02 '15 at 12:27
  • Thank you!! I just included the DeploymentItem attribute onto one of my test classes and it sorted every other failing test class that need the specific file. – r0bb077 Mar 26 '18 at 23:47