How to deploy additional test files with .runsettings?

936 Views Asked by At

I migrated from TPv1 to TPv2 (Test Platform v2). I run my tests by using vstest.console.exe. I used .testsettings file for deploying additional files that my tests required (usually they are XML with some data). The skeleton of my solution is the following:

enter image description here

My TestSettings1.testsettings is the following:

enter image description here

I use this command for running my tests:

@SET LOCAL_SETTINGS=C:\data\Development\Solution14
@SET VSTEST_CONSOLE="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/Extensions/TestPlatform/vstest.console.exe"
%VSTEST_CONSOLE% C:\data\Development\Solution14\UnitTestProject1\bin\debug\UnitTestProject1.dll ^
/Settings:%LOCAL_SETTINGS%\TestSettings1.testsettings 

It's very convenient using .testsettings for deploying items.

So, due to some reasons I can't use .testsettings any more, but I can use .runsettings and DeploymentItem attribute.

With .testsettings I don't have to add a piece of code to each project in order to deploy my files. I just use /Settings flag with vstest.console.exe and this deployment applies to project which I want. With DeploymentItem I should use some code in each unit test project. These parts of code are the same and I don't like it. I don't want to add the same code to each project.

The question: What is the best way to apply the same deployment behavior for each project without writing repetitive code.

Currently I use build-events and xcopy in order to copy them to DeploymentItems folder (I create it by mkdir in build-event) of each bin/Debug folder. After that I add [DeploymentItem("DeploymentItems")] which deploys all files from this folder. It doesn't looks good because I have 3 identical batch of build-events for each .csproj. And if I add new .xml data I will need to add new build-event instruction to each .csproj again. When I used .testsettings I didn't have this problem.

0

There are 0 best solutions below