stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.76k stars 175 forks source link

Is there a recomended way for running stryker against a test project that references multiple projects? #1150

Closed raschmitt closed 4 years ago

raschmitt commented 4 years ago

I'm currently using stryker to run mutations against a test project that references multiple projects:

<ItemGroup>
  <ProjectReference Include="..\..\src\Api.csproj" />
  <ProjectReference Include="..\..\src\Domain.csproj" />
  <ProjectReference Include="..\..\src\Infra.csproj" />
</ItemGroup>

What I'm currently doing is creating multiple configuration files and running mutations for each config separately.

stryker-config-api.json stryker-config-domain.json stryker-config-infra.json

Is this the way to go? Or there is a better approach?

rouke-broersma commented 4 years ago

It is not standard to use one test project for multiple source projects, and so we haven't designed Stryker to work in this way. Multiple configurations is the way to go if you insist on this configuration. Or, you can simply split out your tests in separate projects.

Does that answer your question?

raschmitt commented 4 years ago

@Mobrockers yes it does, thanks.

For anyone reading this in the future, I ended up automatizing my run strategy with the following command in a .bat file:

for %%p in (api, domain, infra) do dotnet stryker -cp stryker-config-%%p.json
richardwerkman commented 4 years ago

@raschmitt There is another way actually. You would still have to move your projects but wont have to split your test project.

We have the possibility to run from the project under test location as well as running from the test project location. If you move your Api, Domain and Infra projects into seperate folders (like the standard for .net) you can run from each folder without multiple config files.

So your project structure should look like:

src
-- Api
---- Api.csproj
-- Domain
---- Domain.csproj
-- Infra
---- Infra.csproj
-- Tests
---- Tests.csproj

You do have to pass the test project location if you do that. It looks like:

dotnet stryker --test-projects "['../MyProject.UnitTests/MyProject.UnitTests.csproj']"

*note that splitting your test project is the better way to solve this.

rouke-broersma commented 4 years ago

Right, I forgot about that feature! @raschmitt