Closed prw56 closed 1 year ago
Use ms code coverage or look at AdjacentBuildOutput
@tonyhallett Was the issue fixed? I assumed your answer was a workaround
The behaviour you see is documented and cannot be changed. Ms code coverage does not require dll copying, runs once and runs only the tests that you select.
If you really need the old style then AdjacentBuildOutput for a Net 6 project:
File.AppendAllText(outputPath, TestContext.CurrentContext.TestDirectory);
\DemoFCC\TestProject1\bin\Debug\net6.0 \DemoFCC\TestProject1\bin\Debug\fine-code-coverage-net6.0
Perhaps this will suffice.
Or if you are accessing resources then embed them in the test assembly https://korzh.com/blog/embedded-resources-testing-projects
Installed product versions
Description
When writing tests with paths that depend on the Nunit TestContext.CurrentContext.TestDirectory property, coverage will fail b/c the value of the property at coverage time is different from test execution time.
Steps to recreate
var curDir = TestContext.CurrentContext.TestDirectory; File.AppendAllText(@"C:\Users\Skull\Desktop\output.txt", $"\n{curDir}");
normalTestPath normalTestPath\fine-code-coverage\build-output
Current behavior
When coverage runs the tests "\fine-code-coverage\build-output" is appended to the end of TestContext.CurrentContext.TestDirectory
Expected behavior
Value of TestContext.CurrentContext.TestDirectory should be the same at coverage time as run time.