How to change Working Directory when running unit test from Visual Studio Test Explorer

859 Views Asked by At

For my new project, I installed Visual Studio 2022, when my co-workers are still using Visual Studio 2019.

Most of the tests are failing on my computer, and after a bit of troubleshooting, I found out that it is due to a change of working directory when running the tests. Instead of working into the generated bin folder or something like that, my tests are executed into the AppData\Local\Temp folder:

System.IO.Directory.GetCurrentDirectory();

"C:\Users\91002969\AppData\Local\Temp"

=> All the relative paths we are using in the test projects are no longer valid.

For example:

Here is the project structure:

Project
|-Fixture
|  \_ NoPalmsTables.IB
\_Project.csproj

The file "NoPalmsTables.IB" is not copied to the output directory and has no build action associated. During the test, the following line is executed:

var path = Path.GetFullPath("../../Fixtures/NoPalmsTables.IB");

In Visual Studio 2022, I get the following results

"C:\Users\91002969\AppData\Fixtures\NoPalmsTables.IB"

In Visual Studio 2019, my co-worker gets the following result:

"C:\Users\90026496\PATH_TO_WORKSPACE\src\Project\Fixtures\NoPalmsTables.IB"

My guess is that it is due to the migration to VS2022. Is there a way to tell Visual Studio to run the test in a specific folder instead of AppData?

I don't know if it is relevant but we are using NUnit2 to test our application (we are studying the possibility to migrate to version 3). Finally, the application targets .NET 4.7.2.

1

There are 1 best solutions below

0
fharreau On

Well ... I ran a git clean command to completely clean my workspace and ... it suddently works fine ...

Here is the command I used:

git clean -d -f -x

Not sure of what happened...