Is it possible to pass MSBuild's property in Visual Studio's test explorer?

78 Views Asked by At

I know I could do something like this:

dotnet test myproject.csproj /p:IsTest=true

and in myproject.csproj:

  <PropertyGroup>
    ...
    <DefineConstants Condition=" '$(IsTest)' == 'true' ">$(DefineConstants);TEST</DefineConstants>
  </PropertyGroup>

And this will allow me to selectively put in or out some portion of codes that should or shouldn't be executed/included when I only want to run a test/unit test. (by put any codes behind #if TEST ... #endif or #if !TEST ... #endif)

I want to know, can I also do something like this when I run a test via visual studio built-in test explorer?

1

There are 1 best solutions below

0
Wasenshi On

I solved the problem by using build configuration.

enter image description here

And then add symbol manually for each project that requires it.

enter image description here

So, create a new build profile (configuration) specifically for unit test and customize what you need directly inside each projects. When you want to run a test via visual studio, you change to this new build config before you hit the run test button.