I am new to unit testing and I am trying to test my code with deployed file. Unfortunately this file does not get copied, when starting the test.
The file to copy is located here:
SolutionDirectory/UnitTestProject/data/testCourseData.xml
This is my test code (i shortened it):
[TestMethod]
[DeploymentItem("UnitTestProject\\data\\testCourseData.xml", "data")]
public void TestCourseConstructor()
{
...
courseActual.ReadXMLConfig(@"data\testCourseData.xml");
...
}
I did some research and I went through several solution approachs:
I have set the xml file build settings to Resource and also to Embedded resource and to Always copy
In older posts they say I have to navigate to Test->Test settings->Deployment and activate deployment, but this menu seems to be no longer existing in newer versions of Visual Studio (I am using VS Pro 2022 64Bit, V17.8.7)
I have added a .runsettings file to UnitTestProject (location now UnitTestProject/.runsettings) with the following content:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- configuration elements -->
<MSTest>
<DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
<DeploymentEnabled>True</DeploymentEnabled>
</MSTest>
</RunSettings>
- I chose the option Test->Configure Runtimesettings->Choose Runsettings file and selected the file above.
None of those things are working.
In addition the posts in Stackoverflow are all extremely old. Should I use nUnit instead?
Thanks in advance for your advices!
EDIT: I forgot to add the error message on test end.
Test method UnitTestProject.UnitTest_Course.TestCourseConstructor threw exception:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'G:\NewFolderStructure\Creative\Programming\C#\WPF\LearningManagementSystem\TestResults\Deploy_jensz 20240322T175537\Out\data\testCourseData.xml'.