I read a lot of posts on Stackoverflow (the post is 12 years old) and in different blogs but usually they are very old. I'm using Visual Studio 2022 with Azure DevOps.
In my test project, I want to read the file _json1.json` under the jsontests folder.
In the test code I added the DeploymentItem
annotation
[TestMethod]
[DeploymentItem(@"jsontest\json1.json", "jsontest")]
public void LoadJson_SystemTextJson_3Textbox_1radiobutton()
{
// ...
var path = @"jsontest\json1.json";
string jsonFromFile = System.IO.File.ReadAllText(path);
// ...
}
The property of this file is Copy to Output Directory
on Copy Always
. Also, in the project I added a file
In the root of the test project I added a .runsettings
file
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<MaxCpuCount>1</MaxCpuCount>
<ResultsDirectory>..\Tests\TestResults</ResultsDirectory>
<TargetPlatform>x64</TargetPlatform>
</RunConfiguration>
<DeploymentEnabled>True</DeploymentEnabled>
</RunSettings>
I tried to run the pipeline in Azure DevOps but I get always the same error
Test Run deployment issue: Failed to get the file for deployment item 'jsontest\json1.json' (output directory 'jsontest'): System.IO.FileNotFoundException: Could not find file '/home/vsts/work/1/s/PSC.Survey.Shared.Validation.Tests/bin/Release/net6.0/jsontest\json1.json'.