stryker-net icon indicating copy to clipboard operation
stryker-net copied to clipboard

Exclude folder path from mutation in stryker-config

Open gentcod opened this issue 1 year ago • 14 comments

I am trying to exclude DB migrations from mutation.

The code for the DB migrations is auto generated by Entity Framework Core and it makes no sense to include them in the mutation as there are a lot of hard coded string values. It gets the mutants that are not covered.

This is a sample of code generated that needs to be excluded: migrationBuilder.CreateTable( name: "RecipeRatings", columns: table => new { Id = table.Column<int>(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), RecipeId = table.Column<int>(type: "INTEGER", nullable: false), RatingNum = table.Column<int>(type: "INTEGER", nullable: false), Comment = table.Column<string>(type: "TEXT", nullable: true) },

gentcod avatar Dec 12 '23 05:12 gentcod

Did you try the mutate option?

rouke-broersma avatar Dec 12 '23 05:12 rouke-broersma

I excluded the methods using "ignore-methods" but the strings and boolean values are being highlighted for mutation, categorized under No Coverage

I have about 100+ mutants being highlighted from just that file.

gentcod avatar Dec 12 '23 05:12 gentcod

Ignore methods is not the same as mutate. Try the mutate option. https://stryker-mutator.io/docs/stryker-net/configuration/#mutate-glob

rouke-broersma avatar Dec 12 '23 06:12 rouke-broersma

I am not familiar with EF inner workings, but Stryker normally does not mutate generated code. To be specific, it does not mutate build time generated code, plus a bunch of well known patterns.

dupdob avatar Dec 12 '23 08:12 dupdob

It doesn't but instead of ignoring the contents, it categorizes it as mutants that are not covered.

Not Covered mutants fall are regarded as survived mutants, so still affecting the mutation score

I noticed it ignored 2 other files in the same directory though; EF Core generates 3 files when a migration is initialized.

gentcod avatar Dec 12 '23 09:12 gentcod

I am not familiar with EF inner workings, but Stryker normally does not mutate generated code. To be specific, it does not mutate build time generated code, plus a bunch of well known patterns.

Iirc ef doesn't consider it generated code because you should always manually check and modify migrations, so they refuse to place the generated code attribute.

rouke-broersma avatar Dec 12 '23 09:12 rouke-broersma

It doesn't but instead of ignoring the contents, it categorizes it as mutants that are not covered.

Not Covered mutants fall are regarded as survived mutants, so still affecting the mutation score

I noticed it ignored 2 other files in the same directory though; EF Core generates 3 files when a migration is initialized.

It should be marked as ignored when excluding using the mutate option. Could you share your full configuration or your debug log file?

Are you using since or baseline?

rouke-broersma avatar Dec 12 '23 09:12 rouke-broersma

I am not familiar with EF inner workings, but Stryker normally does not mutate generated code. To be specific, it does not mutate build time generated code, plus a bunch of well known patterns.

Iirc ef doesn't consider it generated code because you should always manually check and modify migrations, so they refuse to place the generated code attribute.

Well, yeah I understand but there are still a lot of hard coded values that could be mutated.

gentcod avatar Dec 12 '23 09:12 gentcod

This is the configuration I have used so far: { "stryker-config": { "ignore-methods": [ "*migrationBuilder.CreateTable", "*migrationBuilder.CreateIndex", "*migrationBuilder.DropTable", "*Column", "*Annotation", "*PrimaryKey", "*ForeignKey" ], "thresholds": { "high": 80, "low": 60, "break": 0 }, "reporters": [ "progress", "html", "cleartext" ] } }

gentcod avatar Dec 12 '23 09:12 gentcod

@gentcod The option you are using won't work in this case. ignore-methods will only ignore the invocations of those methods. Not the declarations. So the behaviour you're seeing is by design. In this case you could use stryker comments or the mutate option.

See: https://stryker-mutator.io/docs/stryker-net/ignore-mutations/ for an extensive guide on how to ignore mutations.

richardwerkman avatar Dec 13 '23 15:12 richardwerkman

@richardwerkman oh I get but in cases where there are strings in other test suites, that implies that they would be overlooked unless there is a way for me to ignore specific strings. If there is, please do let me know, thank you.

gentcod avatar Dec 13 '23 21:12 gentcod

I read the documentation and saw exclude-mutation referenced on the page for ignore-mutations docs but it's not available on the configuration page.

gentcod avatar Dec 13 '23 21:12 gentcod

I read the documentation and saw exclude-mutation referenced on the page for ignore-mutations docs but it's not available on the configuration page.

Could you link to these docs?

rouke-broersma avatar Dec 14 '23 05:12 rouke-broersma

https://stryker-mutator.io/docs/stryker-net/mutations/

gentcod avatar Dec 14 '23 05:12 gentcod

I'm updating those docs, it should not be called exclude-mutations.

As for your original issue, the method to use to ignore those declarations is to use stryker comments. See: https://stryker-mutator.io/docs/stryker-net/ignore-mutations/#stryker-comments

rouke-broersma avatar Jun 07 '24 14:06 rouke-broersma