I have some SpecFlow tests in a "SpecFlowTests" project in VS to run and they need some test data files. I was using a .testsettings file to deploy the files and it worked. However, the new MsTest agent does not support .testsettings anymore so I need to find another solution to deploy the files.
The test data files have the "Copy to Output Directory" set to "Copy Always". They are copied in the output directory and I can reference them in the code by getting the output directory in the following way:
public static string AssemblyLocation()
{
var assembly = Assembly.GetExecutingAssembly();
var codebase = new Uri(assembly.CodeBase);
var path = codebase.LocalPath;
return path;
}
This approach works when running the tests locally or when running them as part of the build from TFS, it looks for the files in the following location:
...\SpecFlowTests\bin\Debug\Helpers\TestDataFile.txt
However, when trying to run them as part of the release in TFS, it looks for the test data files in the Out folder of the TestResults directory and it cannot find them there.
C:\buildagent1\_work\r1\a\TestResults\Out\Helpers\TestDataFile.txt
I have then tried to set a DeploymentItem attribute on the BeforeFeature method in the tests, but it looks like it does not work, it should deploy the test data files to the Out folder in TestResults, but it does not.
So I need a common solution to work in all three situations (run tests locally, run them from TFS build, run them from TFS release).
I am relatively new at this, so any advice is appreciated.
Thanks!
[DeploymentItem] attributes do not work on the BeforeFeature method. They have to put on the real testmethod/testclass.
Since SpecFlow 2.2 you can specify the deploymentitems in your feature files to get the attributes generated at the correct location. Put an
@MsTest:DeploymentItem:Helpers\TestDataFile.txt
to your feature.Examples from our test suite: https://github.com/SpecFlowOSS/SpecFlow/blob/master/Tests/TechTalk.SpecFlow.Specs/Features/UnitTestProviderSpecific/MsTest/DeploymentItem.feature