forked from pester/Pester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestResults.Tests.ps1
575 lines (487 loc) · 26.4 KB
/
TestResults.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
Set-StrictMode -Version Latest
InModuleScope Pester {
Describe "Write nunit test results (Legacy)" {
Setup -Dir "Results"
It "should write a successful test result" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Mocked Describe')
$TestResults.AddTestResult("Successful testcase","Passed",(New-TimeSpan -Seconds 1))
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile -LegacyFormat
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestCase = $xmlResult.'test-results'.'test-suite'.'results'.'test-suite'.'results'.'test-case'
$xmlTestCase.name | Should Be "Successful testcase"
$xmlTestCase.result | Should Be "Success"
$xmlTestCase.time | Should Be "1"
}
It "should write a failed test result" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Mocked Describe')
$time = [TimeSpan]::FromSeconds(2.5)
$TestResults.AddTestResult("Failed testcase","Failed",$time,'Assert failed: "Expected: Test. But was: Testing"','at line: 28 in C:\Pester\Result.Tests.ps1')
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile -LegacyFormat
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestCase = $xmlResult.'test-results'.'test-suite'.'results'.'test-suite'.'results'.'test-case'
$xmlTestCase.name | Should Be "Failed testcase"
$xmlTestCase.result | Should Be "Failure"
$xmlTestCase.time | Should Be "2.5"
$xmlTestCase.failure.message | Should Be 'Assert failed: "Expected: Test. But was: Testing"'
$xmlTestCase.failure.'stack-trace' | Should Be 'at line: 28 in C:\Pester\Result.Tests.ps1'
}
It "should write the test summary" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Mocked Describe')
$TestResults.AddTestResult("Testcase","Passed",(New-TimeSpan -Seconds 1))
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile -LegacyFormat
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestResult = $xmlResult.'test-results'
$xmlTestResult.total | Should Be 1
$xmlTestResult.failures | Should Be 0
$xmlTestResult.date | Should Be $true
$xmlTestResult.time | Should Be $true
}
it "should write the test-suite information" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Mocked Describe')
$TestResults.AddTestResult("Successful testcase","Passed",[timespan]10000000) #1.0 seconds
$TestResults.AddTestResult("Successful testcase","Passed",[timespan]11000000) #1.1 seconds
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile -LegacyFormat
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestResult = $xmlResult.'test-results'.'test-suite'.results.'test-suite'
$description = $null
if ($xmlTestResult.PSObject.Properties['description'])
{
$description = $xmlTestResult.description
}
$xmlTestResult.type | Should Be "Powershell"
$xmlTestResult.name | Should Be "Mocked Describe"
$description | Should BeNullOrEmpty
$xmlTestResult.result | Should Be "Success"
$xmlTestResult.success | Should Be "True"
$xmlTestResult.time | Should Be 2.1
}
it "should write two test-suite elements for two describes" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Describe #1')
$TestResults.AddTestResult("Successful testcase","Passed",(New-TimeSpan -Seconds 1))
$TestResults.LeaveDescribe()
$testResults.EnterDescribe('Describe #2')
$TestResults.AddTestResult("Failed testcase","Failed",(New-TimeSpan -Seconds 2))
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile -LegacyFormat
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestSuite1 = $xmlResult.'test-results'.'test-suite'.results.'test-suite'[0]
$description = $null
if ($xmlTestSuite1.PSObject.Properties['description'])
{
$description = $xmlTestSuite1.description
}
$xmlTestSuite1.name | Should Be "Describe #1"
$description | Should BeNullOrEmpty
$xmlTestSuite1.result | Should Be "Success"
$xmlTestSuite1.success | Should Be "True"
$xmlTestSuite1.time | Should Be 1.0
$xmlTestSuite2 = $xmlResult.'test-results'.'test-suite'.results.'test-suite'[1]
$description = $null
if ($xmlTestSuite2.PSObject.Properties['description'])
{
$description = $xmlTestSuite2.description
}
$xmlTestSuite2.name | Should Be "Describe #2"
$description | Should BeNullOrEmpty
$xmlTestSuite2.result | Should Be "Failure"
$xmlTestSuite2.success | Should Be "False"
$xmlTestSuite2.time | Should Be 2.0
}
it "should write parent results in tree correctly" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Failed')
$TestResults.AddTestResult("Failed","Failed")
$TestResults.AddTestResult("Skipped","Skipped")
$TestResults.AddTestResult("Pending","Pending")
$TestResults.AddTestResult("Passed","Passed")
$TestResults.LeaveDescribe()
$testResults.EnterDescribe('Skipped')
$TestResults.AddTestResult("Skipped","Skipped")
$TestResults.AddTestResult("Pending","Pending")
$TestResults.AddTestResult("Passed","Passed")
$TestResults.LeaveDescribe()
$testResults.EnterDescribe('Pending')
$TestResults.AddTestResult("Pending","Pending")
$TestResults.AddTestResult("Passed","Passed")
$TestResults.LeaveDescribe()
$testResults.EnterDescribe('Passed')
$TestResults.AddTestResult("Passed","Passed")
$TestResults.LeaveDescribe()
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestSuite1 = $xmlResult.'test-results'.'test-suite'.results.'test-suite'[0]
$xmlTestSuite1.name | Should Be "Failed"
$xmlTestSuite1.result | Should Be "Failure"
$xmlTestSuite1.success | Should Be "False"
$xmlTestSuite2 = $xmlResult.'test-results'.'test-suite'.results.'test-suite'[1]
$xmlTestSuite2.name | Should Be "Skipped"
$xmlTestSuite2.result | Should Be "Skipped"
$xmlTestSuite2.success | Should Be "True"
$xmlTestSuite3 = $xmlResult.'test-results'.'test-suite'.results.'test-suite'[2]
$xmlTestSuite3.name | Should Be "Pending"
$xmlTestSuite3.result | Should Be "Inconclusive"
$xmlTestSuite3.success | Should Be "True"
$xmlTestSuite4 = $xmlResult.'test-results'.'test-suite'.results.'test-suite'[3]
$xmlTestSuite4.name | Should Be "Passed"
$xmlTestSuite4.result | Should Be "Success"
$xmlTestSuite4.success | Should Be "True"
}
it "should write the environment information" {
$state = New-PesterState "."
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $state $testFile -LegacyFormat
$xmlResult = [xml] (Get-Content $testFile)
$xmlEnvironment = $xmlResult.'test-results'.'environment'
$xmlEnvironment.'os-Version' | Should Be $true
$xmlEnvironment.platform | Should Be $true
$xmlEnvironment.cwd | Should Be (Get-Location).Path
if ($env:Username) {
$xmlEnvironment.user | Should Be $env:Username
}
$xmlEnvironment.'machine-name' | Should Be $env:ComputerName
}
it "Should validate test results against the nunit 2.5 schema" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Describe #1')
$TestResults.AddTestResult("Successful testcase","Passed",(New-TimeSpan -Seconds 1))
$TestResults.LeaveDescribe()
$testResults.EnterDescribe('Describe #2')
$TestResults.AddTestResult("Failed testcase","Failed",(New-TimeSpan -Seconds 2))
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile -LegacyFormat
$xml = [xml] (Get-Content $testFile)
$schemePath = (Get-Module -Name Pester).Path | Split-Path | Join-Path -ChildPath "nunit_schema_2.5.xsd"
$xml.Schemas.Add($null,$schemePath) > $null
{ $xml.Validate({throw $args.Exception }) } | Should Not Throw
}
it "handles special characters in block descriptions well -!@#$%^&*()_+`1234567890[];'',./""- " {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Describe -!@#$%^&*()_+`1234567890[];'',./"- #1')
$TestResults.AddTestResult("Successful testcase -!@#$%^&*()_+`1234567890[];'',./""-","Passed",(New-TimeSpan -Seconds 1))
$TestResults.LeaveDescribe()
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile -LegacyFormat
$xml = [xml] (Get-Content $testFile)
$schemePath = (Get-Module -Name Pester).Path | Split-Path | Join-Path -ChildPath "nunit_schema_2.5.xsd"
$xml.Schemas.Add($null,$schemePath) > $null
{ $xml.Validate({throw $args.Exception }) } | Should Not Throw
}
Context 'Exporting Parameterized Tests (New Legacy)' {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Mocked Describe')
$TestResults.AddTestResult(
'Parameterized Testcase One',
'Passed',
(New-TimeSpan -Seconds 1),
$null,
$null,
'Parameterized Testcase <A>',
@{ Parameter = 'One' }
)
$TestResults.AddTestResult(
'Parameterized Testcase <A>',
'Failed',
(New-TimeSpan -Seconds 1),
'Assert failed: "Expected: Test. But was: Testing"',
'at line: 28 in C:\Pester\Result.Tests.ps1',
'Parameterized Testcase <A>',
@{ Parameter = 'Two' }
)
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile -LegacyFormat
$xmlResult = [xml] (Get-Content $testFile)
It 'should write parameterized test results correctly' {
$xmlTestSuite = $xmlResult.'test-results'.'test-suite'.'results'.'test-suite'.'results'.'test-suite'
$description = $null
if ($xmlTestSuite.PSObject.Properties['description'])
{
$description = $xmlTestSuite.description
}
$xmlTestSuite.name | Should Be 'Parameterized Testcase <A>'
$description | Should BeNullOrEmpty
$xmlTestSuite.type | Should Be 'ParameterizedTest'
$xmlTestSuite.result | Should Be 'Failure'
$xmlTestSuite.success | Should Be 'False'
$xmlTestSuite.time | Should Be '2'
foreach ($testCase in $xmlTestSuite.results.'test-case')
{
$testCase.Name | Should Match '^Parameterized Testcase (One|<A>)$'
$testCase.time | Should Be 1
}
}
it 'Should validate test results against the nunit 2.5 schema' {
$schemaPath = (Get-Module -Name Pester).Path | Split-Path | Join-Path -ChildPath "nunit_schema_2.5.xsd"
$null = $xmlResult.Schemas.Add($null,$schemaPath)
{ $xmlResult.Validate({throw $args.Exception }) } | Should Not Throw
}
}
}
Describe "Write nunit test results (Newer format)" {
Setup -Dir "Results"
It "should write a successful test result" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Mocked Describe')
$TestResults.AddTestResult("Successful testcase",'Passed',(New-TimeSpan -Seconds 1))
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestCase = $xmlResult.'test-results'.'test-suite'.'results'.'test-suite'.'results'.'test-case'
$xmlTestCase.name | Should Be "Mocked Describe.Successful testcase"
$xmlTestCase.result | Should Be "Success"
$xmlTestCase.time | Should Be "1"
}
It "should write a failed test result" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Mocked Describe')
$time = [TimeSpan]25000000 #2.5 seconds
$TestResults.AddTestResult("Failed testcase",'Failed',$time,'Assert failed: "Expected: Test. But was: Testing"','at line: 28 in C:\Pester\Result.Tests.ps1')
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestCase = $xmlResult.'test-results'.'test-suite'.'results'.'test-suite'.'results'.'test-case'
$xmlTestCase.name | Should Be "Mocked Describe.Failed testcase"
$xmlTestCase.result | Should Be "Failure"
$xmlTestCase.time | Should Be "2.5"
$xmlTestCase.failure.message | Should Be 'Assert failed: "Expected: Test. But was: Testing"'
$xmlTestCase.failure.'stack-trace' | Should Be 'at line: 28 in C:\Pester\Result.Tests.ps1'
}
It "should write the test summary" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Mocked Describe')
$TestResults.AddTestResult("Testcase",'Passed',(New-TimeSpan -Seconds 1))
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestResult = $xmlResult.'test-results'
$xmlTestResult.total | Should Be 1
$xmlTestResult.failures | Should Be 0
$xmlTestResult.date | Should Be $true
$xmlTestResult.time | Should Be $true
}
it "should write the test-suite information" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Mocked Describe')
$TestResults.AddTestResult("Successful testcase",'Passed',[timespan]10000000) #1.0 seconds
$TestResults.AddTestResult("Successful testcase",'Passed',[timespan]11000000) #1.1 seconds
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestResult = $xmlResult.'test-results'.'test-suite'.results.'test-suite'
$xmlTestResult.type | Should Be "TestFixture"
$xmlTestResult.name | Should Be "Mocked Describe"
$xmlTestResult.description | Should Be "Mocked Describe"
$xmlTestResult.result | Should Be "Success"
$xmlTestResult.success | Should Be "True"
$xmlTestResult.time | Should Be 2.1
}
it "should write two test-suite elements for two describes" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Describe #1')
$TestResults.AddTestResult("Successful testcase",'Passed',(New-TimeSpan -Seconds 1))
$TestResults.LeaveDescribe()
$testResults.EnterDescribe('Describe #2')
$TestResults.AddTestResult("Failed testcase",'Failed',(New-TimeSpan -Seconds 2))
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile
$xmlResult = [xml] (Get-Content $testFile)
$xmlTestSuite1 = $xmlResult.'test-results'.'test-suite'.results.'test-suite'[0]
$xmlTestSuite1.name | Should Be "Describe #1"
$xmlTestSuite1.description | Should Be "Describe #1"
$xmlTestSuite1.result | Should Be "Success"
$xmlTestSuite1.success | Should Be "True"
$xmlTestSuite1.time | Should Be 1.0
$xmlTestSuite2 = $xmlResult.'test-results'.'test-suite'.results.'test-suite'[1]
$xmlTestSuite2.name | Should Be "Describe #2"
$xmlTestSuite2.description | Should Be "Describe #2"
$xmlTestSuite2.result | Should Be "Failure"
$xmlTestSuite2.success | Should Be "False"
$xmlTestSuite2.time | Should Be 2.0
}
it "should write the environment information" {
$state = New-PesterState "."
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $state $testFile
$xmlResult = [xml] (Get-Content $testFile)
$xmlEnvironment = $xmlResult.'test-results'.'environment'
$xmlEnvironment.'os-Version' | Should Be $true
$xmlEnvironment.platform | Should Be $true
$xmlEnvironment.cwd | Should Be (Get-Location).Path
if ($env:Username) {
$xmlEnvironment.user | Should Be $env:Username
}
$xmlEnvironment.'machine-name' | Should Be $env:ComputerName
}
it "Should validate test results against the nunit 2.5 schema" {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Describe #1')
$TestResults.AddTestResult("Successful testcase",'Passed',(New-TimeSpan -Seconds 1))
$TestResults.LeaveDescribe()
$testResults.EnterDescribe('Describe #2')
$TestResults.AddTestResult("Failed testcase",'Failed',(New-TimeSpan -Seconds 2))
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile
$xml = [xml] (Get-Content $testFile)
$schemePath = (Get-Module -Name Pester).Path | Split-Path | Join-Path -ChildPath "nunit_schema_2.5.xsd"
$xml.Schemas.Add($null,$schemePath) > $null
{ $xml.Validate({throw $args.Exception }) } | Should Not Throw
}
it "handles special characters in block descriptions well -!@#$%^&*()_+`1234567890[];'',./""- " {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Describe -!@#$%^&*()_+`1234567890[];'',./"- #1')
$TestResults.AddTestResult("Successful testcase -!@#$%^&*()_+`1234567890[];'',./""-",'Passed',(New-TimeSpan -Seconds 1))
$TestResults.LeaveDescribe()
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile
$xml = [xml] (Get-Content $testFile)
$schemePath = (Get-Module -Name Pester).Path | Split-Path | Join-Path -ChildPath "nunit_schema_2.5.xsd"
$xml.Schemas.Add($null,$schemePath) > $null
{ $xml.Validate({throw $args.Exception }) } | Should Not Throw
}
Context 'Exporting Parameterized Tests (Newer format)' {
#create state
$TestResults = New-PesterState -Path TestDrive:\
$testResults.EnterDescribe('Mocked Describe')
$TestResults.AddTestResult(
'Parameterized Testcase One',
'Passed',
(New-TimeSpan -Seconds 1),
$null,
$null,
'Parameterized Testcase <A>',
@{Parameter = 'One'}
)
$parameters = New-Object System.Collections.Specialized.OrderedDictionary
$parameters.Add('StringParameter', 'Two')
$parameters.Add('NullParameter', $null)
$parameters.Add('NumberParameter', -42.67)
$TestResults.AddTestResult(
'Parameterized Testcase <A>',
'Failed',
(New-TimeSpan -Seconds 1),
'Assert failed: "Expected: Test. But was: Testing"',
'at line: 28 in C:\Pester\Result.Tests.ps1',
'Parameterized Testcase <A>',
$parameters
)
#export and validate the file
$testFile = "$TestDrive\Results\Tests.xml"
Export-NunitReport $testResults $testFile
$xmlResult = [xml] (Get-Content $testFile)
It 'should write parameterized test results correctly' {
$xmlTestSuite = $xmlResult.'test-results'.'test-suite'.'results'.'test-suite'.'results'.'test-suite'
$xmlTestSuite.name | Should Be 'Mocked Describe.Parameterized Testcase <A>'
$xmlTestSuite.description | Should Be 'Parameterized Testcase <A>'
$xmlTestSuite.type | Should Be 'ParameterizedTest'
$xmlTestSuite.result | Should Be 'Failure'
$xmlTestSuite.success | Should Be 'False'
$xmlTestSuite.time | Should Be '2'
$testCase1 = $xmlTestSuite.results.'test-case'[0]
$testCase2 = $xmlTestSuite.results.'test-case'[1]
$testCase1.Name | Should Be 'Mocked Describe.Parameterized Testcase One'
$testCase1.Time | Should Be 1
$testCase2.Name | Should Be 'Mocked Describe.Parameterized Testcase <A>("Two",null,-42.67)'
$testCase2.Time | Should Be 1
}
it 'Should validate test results against the nunit 2.5 schema' {
$schemaPath = (Get-Module -Name Pester).Path | Split-Path | Join-Path -ChildPath "nunit_schema_2.5.xsd"
$null = $xmlResult.Schemas.Add($null,$schemaPath)
{ $xmlResult.Validate({throw $args.Exception }) } | Should Not Throw
}
}
}
Describe "Get-TestTime" {
function Using-Culture {
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[ScriptBlock]$ScriptBlock,
[System.Globalization.CultureInfo]$Culture='en-US'
)
$oldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
try
{
[System.Threading.Thread]::CurrentThread.CurrentCulture = $Culture
$ExecutionContext.InvokeCommand.InvokeScript($ScriptBlock)
}
finally
{
[System.Threading.Thread]::CurrentThread.CurrentCulture = $oldCulture
}
}
It "output is culture agnostic" {
#on cs-CZ, de-DE and other systems where decimal separator is ",". value [double]3.5 is output as 3,5
#this makes some of the tests fail, it could also leak to the nUnit report if the time was output
$TestResult = New-Object -TypeName psObject -Property @{ Time = [timespan]35000000 } #3.5 seconds
#using the string formatter here to know how the string will be output to screen
$Result = { Get-TestTime -Tests $TestResult | Out-String -Stream } | Using-Culture -Culture de-DE
$Result | Should Be "3.5"
}
It "Time is measured in seconds with 0,1 millisecond as lowest value" {
$TestResult = New-Object -TypeName psObject -Property @{ Time = [timespan]1000 }
Get-TestTime -Tests $TestResult | Should Be 0.0001
$TestResult = New-Object -TypeName psObject -Property @{ Time = [timespan]100 }
Get-TestTime -Tests $TestResult | Should Be 0
$TestResult = New-Object -TypeName psObject -Property @{ Time = [timespan]1234567 }
Get-TestTime -Tests $TestResult | Should Be 0.1235
}
}
Describe "GetFullPath" {
It "Resolves non existing path correctly" {
pushd TestDrive:\
$p = GetFullPath notexistingfile.txt
popd
$p | Should Be (Join-Path $TestDrive notexistingfile.txt)
}
It "Resolves existing path correctly" {
pushd TestDrive:\
New-Item -ItemType File -Name existingfile.txt
$p = GetFullPath existingfile.txt
popd
$p | Should Be (Join-Path $TestDrive existingfile.txt)
}
It "Resolves full path correctly" {
GetFullPath C:\Windows\System32\notepad.exe | Should Be C:\Windows\System32\notepad.exe
}
}
}