@@ -2234,8 +2234,6 @@ i -PassThru:$PassThru {
22342234
22352235
22362236 t " total time is roughly the same as time measured externally (measured on a second test)" {
2237- # this is the same as above, if I add one time setups then the framework time should grow
2238- # but not the user code time
22392237 $container = @ {
22402238 Test = $null
22412239 Block = $null
@@ -2298,8 +2296,6 @@ i -PassThru:$PassThru {
22982296 }
22992297
23002298 t " total time is roughly the same as time measured externally (on many tests)" {
2301- # this is the same as above, if I add one time setups then the framework time should grow
2302- # but not the user code time
23032299 $container = @ {
23042300 Test = $null
23052301 Block = $null
@@ -2357,6 +2353,54 @@ i -PassThru:$PassThru {
23572353
23582354 # TODO: revisit the difference on many tests, it is still missing some parts of the common discovery processing I guess (replicates on 10k tests)
23592355 }
2356+
2357+ t " OneTimeTestSetup and OneTimeTestTeardown is measured as user code in block" {
2358+ $actual = Invoke-Test - SessionState $ExecutionContext.SessionState - BlockContainer (
2359+ New-BlockContainerObject - ScriptBlock {
2360+ New-Block - Name ' b1' {
2361+ New-OneTimeTestSetup {
2362+ Start-Sleep - Milliseconds 50
2363+ }
2364+ New-OneTimeTestTeardown {
2365+ Start-Sleep - Milliseconds 50
2366+ }
2367+ New-Test ' t1' {
2368+ $true
2369+ }
2370+ }
2371+ }
2372+ )
2373+
2374+ $actual.UserDuration.TotalMilliseconds -ge 100 | Verify- True
2375+ $actual.Blocks [0 ].UserDuration.TotalMilliseconds -ge 100 | Verify- True
2376+ $actual.Blocks [0 ].OwnDuration.TotalMilliseconds -ge 100 | Verify- True
2377+ # test should not include time spent in block setup/teardown
2378+ $actual.Blocks [0 ].Tests[0 ].UserDuration.TotalMilliseconds -lt 100 | Verify- True
2379+ }
2380+
2381+ t " EachTestSetup and EachTestTeardown is measured as user code in test" {
2382+ $actual = Invoke-Test - SessionState $ExecutionContext.SessionState - BlockContainer (
2383+ New-BlockContainerObject - ScriptBlock {
2384+ New-Block - Name ' b1' {
2385+ New-EachTestSetup {
2386+ Start-Sleep - Milliseconds 50
2387+ }
2388+ New-EachTestTeardown {
2389+ Start-Sleep - Milliseconds 50
2390+ }
2391+ New-Test ' t1' {
2392+ $true
2393+ }
2394+ }
2395+ }
2396+ )
2397+
2398+ $actual.UserDuration.TotalMilliseconds -ge 100 | Verify- True
2399+ $actual.Blocks [0 ].UserDuration.TotalMilliseconds -ge 100 | Verify- True
2400+ # block is not responsible for setup/teardown per test.
2401+ $actual.Blocks [0 ].OwnDuration.TotalMilliseconds -lt 100 | Verify- True
2402+ $actual.Blocks [0 ].Tests[0 ].UserDuration.TotalMilliseconds -ge 100 | Verify- True
2403+ }
23602404 }
23612405
23622406 b " Setup and Teardown on root block" {
0 commit comments