I have a solution which has a console application and unit test.
var target = new Validator();
var targetFile = @"C:\Folder\SubFolder\AnotherSubFolder\Development\DEV\src\UnitTest\TargetFolder\file.xml";
bool actual = target.Validate(targetFile);
Assert.AreEqual(true, actual);
The Validator is located at the console application project, while my file.xml is located at the folder inside the unit test project.
This unit test is passing, however i want to make sure that when i check in this in to my tfs or build server, it can still locate my targetFile.
How am I gonna change the path of the targetFile?
Thanks in advance!
If I understood your issue correctly, it is not good that product code(in console application) depends on an item in the test project, so I recommend you to move file.xml
to the product code project.
To solve your path problem, I think the best approach is to use the Copy to Output Directory property as Copy always or Copy if newer, which you can find in the VS Properties window.
Check out the following steps.
file.xml
in the product project(eg. Data folder).file.xml
in the folder.file.xml
.Build and do unit testing as
Assert.IsTrue(File.Exists(@"Data\file.xml"));
In this case, VS will automatically make the data folder with file.xml
under output folder of test poject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With