@@ -137,63 +137,70 @@ private static void RunUnitTests(BuildContext buildContext, string projectName)
137
137
138
138
var ranTests = false ;
139
139
var failed = false ;
140
- var testTargetFramework = GetTestTargetFramework ( buildContext , projectName ) ;
140
+ var testTargetFrameworks = GetTestTargetFrameworks ( buildContext , projectName ) ;
141
141
142
142
try
143
143
{
144
- if ( IsDotNetCoreProject ( buildContext , projectName ) )
144
+ foreach ( var testTargetFramework in testTargetFrameworks )
145
145
{
146
- buildContext . CakeContext . Information ( $ "Project '{ projectName } ' is a .NET core project, using 'dotnet test' to run the unit tests") ;
147
-
148
- var projectFileName = GetProjectFileName ( buildContext , projectName ) ;
149
-
150
- var dotNetTestSettings = new DotNetTestSettings
151
- {
152
- Configuration = buildContext . General . Solution . ConfigurationName ,
153
- // Loggers = new []
154
- // {
155
- // "nunit;LogFilePath=test-result.xml"
156
- // },
157
- NoBuild = true ,
158
- NoLogo = true ,
159
- NoRestore = true ,
160
- OutputDirectory = System . IO . Path . Combine ( GetProjectOutputDirectory ( buildContext , projectName ) , testTargetFramework ) ,
161
- ResultsDirectory = testResultsDirectory
162
- } ;
163
-
164
- if ( IsNUnitTestProject ( buildContext , projectName ) )
165
- {
166
- dotNetTestSettings . ArgumentCustomization = args => args
167
- . Append ( $ "-- NUnit.TestOutputXml={ testResultsDirectory } ") ;
168
- }
146
+ LogSeparator ( buildContext . CakeContext , "Running tests for target framework {0}" , testTargetFramework ) ;
169
147
170
- if ( IsXUnitTestProject ( buildContext , projectName ) )
148
+ if ( IsDotNetCoreTargetFramework ( buildContext , testTargetFramework ) )
171
149
{
172
- var outputFileName = System . IO . Path . Combine ( testResultsDirectory , $ "{ projectName } .xml") ;
150
+ buildContext . CakeContext . Information ( $ "Project '{ projectName } ' is a .NET core project, using 'dotnet test' to run the unit tests") ;
151
+
152
+ var projectFileName = GetProjectFileName ( buildContext , projectName ) ;
153
+
154
+ var dotNetTestSettings = new DotNetTestSettings
155
+ {
156
+ Configuration = buildContext . General . Solution . ConfigurationName ,
157
+ // Loggers = new []
158
+ // {
159
+ // "nunit;LogFilePath=test-result.xml"
160
+ // },
161
+ NoBuild = true ,
162
+ NoLogo = true ,
163
+ NoRestore = true ,
164
+ OutputDirectory = System . IO . Path . Combine ( GetProjectOutputDirectory ( buildContext , projectName ) , testTargetFramework ) ,
165
+ ResultsDirectory = testResultsDirectory
166
+ } ;
167
+
168
+ if ( IsNUnitTestProject ( buildContext , projectName ) )
169
+ {
170
+ dotNetTestSettings . ArgumentCustomization = args => args
171
+ . Append ( $ "-- NUnit.TestOutputXml={ testResultsDirectory } ") ;
172
+ }
173
+
174
+ if ( IsXUnitTestProject ( buildContext , projectName ) )
175
+ {
176
+ var outputFileName = System . IO . Path . Combine ( testResultsDirectory , $ "{ projectName } .xml") ;
177
+
178
+ dotNetTestSettings . ArgumentCustomization = args => args
179
+ . Append ( $ "-l:trx;LogFileName={ outputFileName } ") ;
180
+ }
181
+
182
+ var processBit = buildContext . Tests . ProcessBit . ToLower ( ) ;
183
+ if ( ! string . IsNullOrWhiteSpace ( processBit ) )
184
+ {
185
+ dotNetTestSettings . Runtime = $ "{ buildContext . Tests . OperatingSystem } -{ processBit } ";
186
+ }
187
+
188
+ buildContext . CakeContext . Information ( $ "Runtime: '{ dotNetTestSettings . Runtime } '") ;
189
+
190
+ buildContext . CakeContext . DotNetTest ( projectFileName , dotNetTestSettings ) ;
173
191
174
- dotNetTestSettings . ArgumentCustomization = args => args
175
- . Append ( $ "-l:trx;LogFileName={ outputFileName } ") ;
192
+ ranTests = true ;
176
193
}
177
-
178
- var processBit = buildContext . Tests . ProcessBit . ToLower ( ) ;
179
- if ( ! string . IsNullOrWhiteSpace ( processBit ) )
194
+ else
180
195
{
181
- dotNetTestSettings . Runtime = $ "win-{ processBit } ";
182
- }
183
-
184
- buildContext . CakeContext . DotNetTest ( projectFileName , dotNetTestSettings ) ;
185
-
186
- ranTests = true ;
187
- }
188
- else
189
- {
190
- buildContext . CakeContext . Information ( $ "Project '{ projectName } ' is a .NET project, using '{ buildContext . Tests . Framework } runner' to run the unit tests") ;
196
+ buildContext . CakeContext . Information ( $ "Project '{ projectName } ' is a .NET project, using '{ buildContext . Tests . Framework } runner' to run the unit tests") ;
191
197
192
- if ( IsNUnitTestProject ( buildContext , projectName ) )
193
- {
194
- RunTestsUsingNUnit ( buildContext , projectName , testTargetFramework , testResultsDirectory ) ;
198
+ if ( IsNUnitTestProject ( buildContext , projectName ) )
199
+ {
200
+ RunTestsUsingNUnit ( buildContext , projectName , testTargetFramework , testResultsDirectory ) ;
195
201
196
- ranTests = true ;
202
+ ranTests = true ;
203
+ }
197
204
}
198
205
}
199
206
}
@@ -273,28 +280,30 @@ private static bool IsXUnitTestProject(BuildContext buildContext, string project
273
280
274
281
//-------------------------------------------------------------
275
282
276
- private static string GetTestTargetFramework ( BuildContext buildContext , string projectName )
283
+ private static IReadOnlyList < string > GetTestTargetFrameworks ( BuildContext buildContext , string projectName )
277
284
{
278
285
// Step 1: if defined, use defined value
279
286
var testTargetFramework = buildContext . Tests . TargetFramework ;
280
287
if ( ! string . IsNullOrWhiteSpace ( testTargetFramework ) )
281
288
{
282
289
buildContext . CakeContext . Information ( "Using test target framework '{0}', specified via the configuration" , testTargetFramework ) ;
283
290
284
- return testTargetFramework ;
291
+ return new [ ]
292
+ {
293
+ testTargetFramework
294
+ } ;
285
295
}
286
296
287
- buildContext . CakeContext . Information ( "Test target framework not specified, auto detecting test target framework " ) ;
297
+ buildContext . CakeContext . Information ( "Test target framework not specified, auto detecting test target frameworks " ) ;
288
298
289
299
var targetFrameworks = GetTargetFrameworks ( buildContext , projectName ) ;
290
- testTargetFramework = targetFrameworks . FirstOrDefault ( ) ;
291
300
292
- buildContext . CakeContext . Information ( "Auto detected test target framework '{0}'" , testTargetFramework ) ;
301
+ buildContext . CakeContext . Information ( "Auto detected test target frameworks '{0}'" , string . Join ( ", " , targetFrameworks ) ) ;
293
302
294
- if ( string . IsNullOrWhiteSpace ( testTargetFramework ) )
303
+ if ( targetFrameworks . Length == 0 )
295
304
{
296
305
throw new Exception ( string . Format ( "Test target framework could not automatically be detected for project '{0]'" , projectName ) ) ;
297
306
}
298
307
299
- return testTargetFramework ;
308
+ return targetFrameworks ;
300
309
}
0 commit comments