11
11
using Stryker . Core . Reporters . Json ;
12
12
using Xunit ;
13
13
14
- namespace IntegrationTests
15
- {
16
- public class ValidateStrykerResults
17
- {
18
- private readonly ReadOnlyCollection < SyntaxKind > _blacklistedSyntaxKindsForMutating =
19
- new ( new [ ]
20
- {
21
- // Usings
22
- SyntaxKind . UsingDirective ,
23
- SyntaxKind . UsingKeyword ,
24
- SyntaxKind . UsingStatement ,
25
- // Comments
26
- SyntaxKind . DocumentationCommentExteriorTrivia ,
27
- SyntaxKind . EndOfDocumentationCommentToken ,
28
- SyntaxKind . MultiLineCommentTrivia ,
29
- SyntaxKind . MultiLineDocumentationCommentTrivia ,
30
- SyntaxKind . SingleLineCommentTrivia ,
31
- SyntaxKind . SingleLineDocumentationCommentTrivia ,
32
- SyntaxKind . XmlComment ,
33
- SyntaxKind . XmlCommentEndToken ,
34
- SyntaxKind . XmlCommentStartToken ,
35
- }
36
- ) ;
37
- private readonly ReadOnlyCollection < SyntaxKind > _parentSyntaxKindsForMutating =
38
- new ( new [ ]
39
- {
40
- SyntaxKind . MethodDeclaration ,
41
- SyntaxKind . PropertyDeclaration ,
42
- SyntaxKind . ConstructorDeclaration ,
43
- SyntaxKind . FieldDeclaration ,
44
- SyntaxKind . OperatorDeclaration ,
45
- SyntaxKind . IndexerDeclaration ,
46
- }
47
- ) ;
48
- private const string MutationReportJson = "mutation-report.json" ;
14
+ namespace Validation ;
49
15
50
- [ Fact ]
51
- [ Trait ( "Category" , "SingleTestProject" ) ]
52
- public async Task CSharp_NetFramework_SingleTestProject ( )
16
+ public class ValidateStrykerResults
17
+ {
18
+ private readonly ReadOnlyCollection < SyntaxKind > _blacklistedSyntaxKindsForMutating =
19
+ new ( new [ ]
53
20
{
54
- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
55
- {
56
- var directory = new DirectoryInfo ( "../../../../../TargetProjects/NetFramework/FullFrameworkApp.Test/StrykerOutput" ) ;
57
- directory . GetFiles ( "*.json" , SearchOption . AllDirectories ) . ShouldNotBeEmpty ( "No reports available to assert" ) ;
58
-
59
- var latestReport = directory . GetFiles ( MutationReportJson , SearchOption . AllDirectories )
60
- . OrderByDescending ( f => f . LastWriteTime )
61
- . First ( ) ;
62
-
63
- using var strykerRunOutput = File . OpenRead ( latestReport . FullName ) ;
64
-
65
- var report = await JsonReportSerialization . DeserializeJsonReportAsync ( strykerRunOutput ) ;
66
-
67
- CheckReportMutants ( report , total : 29 , ignored : 7 , survived : 3 , killed : 7 , timeout : 0 , nocoverage : 11 ) ;
68
- }
21
+ // Usings
22
+ SyntaxKind . UsingDirective ,
23
+ SyntaxKind . UsingKeyword ,
24
+ SyntaxKind . UsingStatement ,
25
+ // Comments
26
+ SyntaxKind . DocumentationCommentExteriorTrivia ,
27
+ SyntaxKind . EndOfDocumentationCommentToken ,
28
+ SyntaxKind . MultiLineCommentTrivia ,
29
+ SyntaxKind . MultiLineDocumentationCommentTrivia ,
30
+ SyntaxKind . SingleLineCommentTrivia ,
31
+ SyntaxKind . SingleLineDocumentationCommentTrivia ,
32
+ SyntaxKind . XmlComment ,
33
+ SyntaxKind . XmlCommentEndToken ,
34
+ SyntaxKind . XmlCommentStartToken ,
69
35
}
36
+ ) ;
37
+ private readonly ReadOnlyCollection < SyntaxKind > _parentSyntaxKindsForMutating =
38
+ new ( new [ ]
39
+ {
40
+ SyntaxKind . MethodDeclaration ,
41
+ SyntaxKind . PropertyDeclaration ,
42
+ SyntaxKind . ConstructorDeclaration ,
43
+ SyntaxKind . FieldDeclaration ,
44
+ SyntaxKind . OperatorDeclaration ,
45
+ SyntaxKind . IndexerDeclaration ,
46
+ }
47
+ ) ;
48
+ private const string MutationReportJson = "mutation-report.json" ;
70
49
71
- [ Fact ]
72
- [ Trait ( "Category" , "SingleTestProject" ) ]
73
- public async Task CSharp_NetCore_SingleTestProject ( )
50
+ [ Fact ]
51
+ [ Trait ( "Category" , "SingleTestProject" ) ]
52
+ public async Task CSharp_NetFramework_SingleTestProject ( )
53
+ {
54
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
74
55
{
75
- var directory = new DirectoryInfo ( "../../../../../TargetProjects/NetCore/NetCoreTestProject.XUnit /StrykerOutput" ) ;
56
+ var directory = new DirectoryInfo ( "../../../../../TargetProjects/NetFramework/FullFrameworkApp.Test /StrykerOutput" ) ;
76
57
directory . GetFiles ( "*.json" , SearchOption . AllDirectories ) . ShouldNotBeEmpty ( "No reports available to assert" ) ;
77
58
78
59
var latestReport = directory . GetFiles ( MutationReportJson , SearchOption . AllDirectories )
@@ -81,116 +62,114 @@ public async Task CSharp_NetCore_SingleTestProject()
81
62
82
63
using var strykerRunOutput = File . OpenRead ( latestReport . FullName ) ;
83
64
84
- var report = await JsonReportSerialization . DeserializeJsonReportAsync ( strykerRunOutput ) ;
65
+ var report = await strykerRunOutput . DeserializeJsonReportAsync ( ) ;
85
66
86
- CheckReportMutants ( report , total : 601 , ignored : 247 , survived : 4 , killed : 9 , timeout : 2 , nocoverage : 308 ) ;
87
- CheckReportTestCounts ( report , total : 11 ) ;
67
+ CheckReportMutants ( report , total : 29 , ignored : 7 , survived : 3 , killed : 7 , timeout : 0 , nocoverage : 11 ) ;
88
68
}
69
+ }
89
70
90
- [ Fact ]
91
- [ Trait ( "Category" , "FSharp " ) ]
92
- public async Task FSharp_SingleTestProject ( )
93
- {
94
- var directory = new DirectoryInfo ( "../../../../../TargetProjects/NetCore/Library.FSharp .XUnit/StrykerOutput" ) ;
95
- directory . GetFiles ( "*.json" , SearchOption . AllDirectories ) . ShouldNotBeEmpty ( "No reports available to assert" ) ;
71
+ [ Fact ]
72
+ [ Trait ( "Category" , "SingleTestProject " ) ]
73
+ public async Task CSharp_NetCore_SingleTestProject ( )
74
+ {
75
+ var directory = new DirectoryInfo ( "../../../../../TargetProjects/NetCore/NetCoreTestProject .XUnit/StrykerOutput" ) ;
76
+ directory . GetFiles ( "*.json" , SearchOption . AllDirectories ) . ShouldNotBeEmpty ( "No reports available to assert" ) ;
96
77
97
- var latestReport = directory
98
- . GetFiles ( MutationReportJson , SearchOption . AllDirectories )
99
- . OrderByDescending ( f => f . LastWriteTime )
100
- . First ( ) ;
78
+ var latestReport = directory . GetFiles ( MutationReportJson , SearchOption . AllDirectories )
79
+ . OrderByDescending ( f => f . LastWriteTime )
80
+ . First ( ) ;
101
81
102
- using var strykerRunOutput = File . OpenRead ( latestReport . FullName ) ;
82
+ using var strykerRunOutput = File . OpenRead ( latestReport . FullName ) ;
103
83
104
- var report = await JsonReportSerialization . DeserializeJsonReportAsync ( strykerRunOutput ) ;
84
+ var report = await strykerRunOutput . DeserializeJsonReportAsync ( ) ;
105
85
106
- CheckReportMutants ( report , total : 0 , ignored : 0 , survived : 0 , killed : 0 , timeout : 0 , nocoverage : 0 ) ;
107
- CheckReportTestCounts ( report , total : 0 ) ;
108
- }
86
+ CheckReportMutants ( report , total : 601 , ignored : 247 , survived : 4 , killed : 9 , timeout : 2 , nocoverage : 308 ) ;
87
+ CheckReportTestCounts ( report , total : 11 ) ;
88
+ }
109
89
110
- [ Fact ]
111
- [ Trait ( "Category" , "MultipleTestProjects" ) ]
112
- public async Task CSharp_NetCore_WithTwoTestProjects ( )
113
- {
114
- var directory = new DirectoryInfo ( "../../../../../TargetProjects/NetCore/Targetproject/StrykerOutput" ) ;
115
- directory . GetFiles ( "*.json" , SearchOption . AllDirectories ) . ShouldNotBeEmpty ( "No reports available to assert" ) ;
90
+ [ Fact ]
91
+ [ Trait ( "Category" , "MultipleTestProjects" ) ]
92
+ public async Task CSharp_NetCore_WithTwoTestProjects ( )
93
+ {
94
+ var directory = new DirectoryInfo ( "../../../../../TargetProjects/NetCore/Targetproject/StrykerOutput" ) ;
95
+ directory . GetFiles ( "*.json" , SearchOption . AllDirectories ) . ShouldNotBeEmpty ( "No reports available to assert" ) ;
116
96
117
- var latestReport = directory . GetFiles ( MutationReportJson , SearchOption . AllDirectories )
118
- . OrderByDescending ( f => f . LastWriteTime )
119
- . First ( ) ;
97
+ var latestReport = directory . GetFiles ( MutationReportJson , SearchOption . AllDirectories )
98
+ . OrderByDescending ( f => f . LastWriteTime )
99
+ . First ( ) ;
120
100
121
- using var strykerRunOutput = File . OpenRead ( latestReport . FullName ) ;
101
+ using var strykerRunOutput = File . OpenRead ( latestReport . FullName ) ;
122
102
123
- var report = await JsonReportSerialization . DeserializeJsonReportAsync ( strykerRunOutput ) ;
103
+ var report = await strykerRunOutput . DeserializeJsonReportAsync ( ) ;
124
104
125
- CheckReportMutants ( report , total : 601 , ignored : 105 , survived : 5 , killed : 11 , timeout : 2 , nocoverage : 447 ) ;
126
- CheckReportTestCounts ( report , total : 21 ) ;
127
- }
105
+ CheckReportMutants ( report , total : 601 , ignored : 105 , survived : 5 , killed : 11 , timeout : 2 , nocoverage : 447 ) ;
106
+ CheckReportTestCounts ( report , total : 21 ) ;
107
+ }
128
108
129
- [ Fact ]
130
- [ Trait ( "Category" , "Solution" ) ]
131
- public async Task CSharp_NetCore_SolutionRun ( )
132
- {
133
- var directory = new DirectoryInfo ( "../../../../../TargetProjects/NetCore/StrykerOutput" ) ;
134
- directory . GetFiles ( "*.json" , SearchOption . AllDirectories ) . ShouldNotBeEmpty ( "No reports available to assert" ) ;
109
+ [ Fact ]
110
+ [ Trait ( "Category" , "Solution" ) ]
111
+ public async Task CSharp_NetCore_SolutionRun ( )
112
+ {
113
+ var directory = new DirectoryInfo ( "../../../../../TargetProjects/NetCore/StrykerOutput" ) ;
114
+ directory . GetFiles ( "*.json" , SearchOption . AllDirectories ) . ShouldNotBeEmpty ( "No reports available to assert" ) ;
135
115
136
- var latestReport = directory . GetFiles ( MutationReportJson , SearchOption . AllDirectories )
137
- . OrderByDescending ( f => f . LastWriteTime )
138
- . First ( ) ;
116
+ var latestReport = directory . GetFiles ( MutationReportJson , SearchOption . AllDirectories )
117
+ . OrderByDescending ( f => f . LastWriteTime )
118
+ . First ( ) ;
139
119
140
- using var strykerRunOutput = File . OpenRead ( latestReport . FullName ) ;
120
+ using var strykerRunOutput = File . OpenRead ( latestReport . FullName ) ;
141
121
142
- var report = await JsonReportSerialization . DeserializeJsonReportAsync ( strykerRunOutput ) ;
122
+ var report = await strykerRunOutput . DeserializeJsonReportAsync ( ) ;
143
123
144
- CheckReportMutants ( report , total : 601 , ignored : 247 , survived : 4 , killed : 9 , timeout : 2 , nocoverage : 308 ) ;
145
- CheckReportTestCounts ( report , total : 23 ) ;
146
- }
124
+ CheckReportMutants ( report , total : 601 , ignored : 247 , survived : 4 , killed : 9 , timeout : 2 , nocoverage : 308 ) ;
125
+ CheckReportTestCounts ( report , total : 23 ) ;
126
+ }
147
127
148
- private void CheckMutationKindsValidity ( IJsonReport report )
128
+ private void CheckMutationKindsValidity ( IJsonReport report )
129
+ {
130
+ foreach ( var file in report . Files )
149
131
{
150
- foreach ( var file in report . Files )
132
+ var syntaxTreeRootNode = CSharpSyntaxTree . ParseText ( file . Value . Source ) . GetRoot ( ) ;
133
+ var textLines = SourceText . From ( file . Value . Source ) . Lines ;
134
+
135
+ foreach ( var mutation in file . Value . Mutants )
151
136
{
152
- var syntaxTreeRootNode = CSharpSyntaxTree . ParseText ( file . Value . Source ) . GetRoot ( ) ;
153
- var textLines = SourceText . From ( file . Value . Source ) . Lines ;
154
-
155
- foreach ( var mutation in file . Value . Mutants )
156
- {
157
- var linePositionSpan = new LinePositionSpan ( new LinePosition ( mutation . Location . Start . Line - 1 , mutation . Location . Start . Column ) , new LinePosition ( mutation . Location . End . Line - 1 , mutation . Location . End . Column ) ) ;
158
- var textSpan = textLines . GetTextSpan ( linePositionSpan ) ;
159
- var node = syntaxTreeRootNode . FindNode ( textSpan ) ;
160
- var nodeKind = node . Kind ( ) ;
161
- _blacklistedSyntaxKindsForMutating . ShouldNotContain ( nodeKind ) ;
162
-
163
- node . AncestorsAndSelf ( ) . ShouldContain ( pn => _parentSyntaxKindsForMutating . Contains ( pn . Kind ( ) ) ) ;
164
- }
137
+ var linePositionSpan = new LinePositionSpan ( new LinePosition ( mutation . Location . Start . Line - 1 , mutation . Location . Start . Column ) , new LinePosition ( mutation . Location . End . Line - 1 , mutation . Location . End . Column ) ) ;
138
+ var textSpan = textLines . GetTextSpan ( linePositionSpan ) ;
139
+ var node = syntaxTreeRootNode . FindNode ( textSpan ) ;
140
+ var nodeKind = node . Kind ( ) ;
141
+ _blacklistedSyntaxKindsForMutating . ShouldNotContain ( nodeKind ) ;
142
+
143
+ node . AncestorsAndSelf ( ) . ShouldContain ( pn => _parentSyntaxKindsForMutating . Contains ( pn . Kind ( ) ) ) ;
165
144
}
166
145
}
146
+ }
167
147
168
- private void CheckReportMutants ( IJsonReport report , int total , int ignored , int survived , int killed , int timeout , int nocoverage )
169
- {
170
- var actualTotal = report . Files . Select ( f => f . Value . Mutants . Count ( ) ) . Sum ( ) ;
171
- var actualIgnored = report . Files . Select ( f => f . Value . Mutants . Count ( m => m . Status == MutantStatus . Ignored . ToString ( ) ) ) . Sum ( ) ;
172
- var actualSurvived = report . Files . Select ( f => f . Value . Mutants . Count ( m => m . Status == MutantStatus . Survived . ToString ( ) ) ) . Sum ( ) ;
173
- var actualKilled = report . Files . Select ( f => f . Value . Mutants . Count ( m => m . Status == MutantStatus . Killed . ToString ( ) ) ) . Sum ( ) ;
174
- var actualTimeout = report . Files . Select ( f => f . Value . Mutants . Count ( m => m . Status == MutantStatus . Timeout . ToString ( ) ) ) . Sum ( ) ;
175
- var actualNoCoverage = report . Files . Select ( f => f . Value . Mutants . Count ( m => m . Status == MutantStatus . NoCoverage . ToString ( ) ) ) . Sum ( ) ;
176
-
177
- report . Files . ShouldSatisfyAllConditions (
178
- ( ) => actualTotal . ShouldBe ( total ) ,
179
- ( ) => actualIgnored . ShouldBe ( ignored ) ,
180
- ( ) => actualSurvived . ShouldBe ( survived ) ,
181
- ( ) => actualKilled . ShouldBe ( killed ) ,
182
- ( ) => actualTimeout . ShouldBe ( timeout ) ,
183
- ( ) => actualNoCoverage . ShouldBe ( nocoverage )
184
- ) ;
185
-
186
- CheckMutationKindsValidity ( report ) ;
187
- }
148
+ private void CheckReportMutants ( IJsonReport report , int total , int ignored , int survived , int killed , int timeout , int nocoverage )
149
+ {
150
+ var actualTotal = report . Files . Select ( f => f . Value . Mutants . Count ( ) ) . Sum ( ) ;
151
+ var actualIgnored = report . Files . Select ( f => f . Value . Mutants . Count ( m => m . Status == MutantStatus . Ignored . ToString ( ) ) ) . Sum ( ) ;
152
+ var actualSurvived = report . Files . Select ( f => f . Value . Mutants . Count ( m => m . Status == MutantStatus . Survived . ToString ( ) ) ) . Sum ( ) ;
153
+ var actualKilled = report . Files . Select ( f => f . Value . Mutants . Count ( m => m . Status == MutantStatus . Killed . ToString ( ) ) ) . Sum ( ) ;
154
+ var actualTimeout = report . Files . Select ( f => f . Value . Mutants . Count ( m => m . Status == MutantStatus . Timeout . ToString ( ) ) ) . Sum ( ) ;
155
+ var actualNoCoverage = report . Files . Select ( f => f . Value . Mutants . Count ( m => m . Status == MutantStatus . NoCoverage . ToString ( ) ) ) . Sum ( ) ;
156
+
157
+ report . Files . ShouldSatisfyAllConditions (
158
+ ( ) => actualTotal . ShouldBe ( total ) ,
159
+ ( ) => actualIgnored . ShouldBe ( ignored ) ,
160
+ ( ) => actualSurvived . ShouldBe ( survived ) ,
161
+ ( ) => actualKilled . ShouldBe ( killed ) ,
162
+ ( ) => actualTimeout . ShouldBe ( timeout ) ,
163
+ ( ) => actualNoCoverage . ShouldBe ( nocoverage )
164
+ ) ;
188
165
189
- private void CheckReportTestCounts ( IJsonReport report , int total )
190
- {
191
- var actualTotal = report . TestFiles . Sum ( tf => tf . Value . Tests . Count ) ;
166
+ CheckMutationKindsValidity ( report ) ;
167
+ }
192
168
193
- actualTotal . ShouldBe ( total ) ;
194
- }
169
+ private void CheckReportTestCounts ( IJsonReport report , int total )
170
+ {
171
+ var actualTotal = report . TestFiles . Sum ( tf => tf . Value . Tests . Count ) ;
172
+
173
+ actualTotal . ShouldBe ( total ) ;
195
174
}
196
175
}
0 commit comments