I have some testing code using condition compilation like below:
public class MyFixture : IDisposable
{
public MyFixture()
{
#if UseMySqlForTesting
... do A
#else
... do B
#endif
}
and also some related files if UseMySqlForTesting
is true:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<UseMySqlForTesting>true</UseMySqlForTesting>
</PropertyGroup>
...
<!-- copy the files if we use mysql, otherwise, don't copy them -->
<ItemGroup Condition="$(UseMySqlForTesting)">
<None Update="MySql.Test.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="other.configuration.files.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Now I'd like to use dotnet test
to test the project.
Question:
Is there an approach like this:
dotnet test /p:UseMySqlForTesting=false
dotnet test /p:UseMySqlForTesting=true
by which it can test the #if
or #else
branch automatically and also copy the related files if required?