Tests in nested contexts not showing results
When I create tests in a nested context, Tests Explorer initially shows the tests in a separate Context at a "sibling" level to the parent Context (within the same Describe), but once I run the tests, any tests in a nested context are removed from Tests Explorer.
The tests do run correctly within Pester (whether executed from within VS or externally), and the output from the test shows in the Output From Tests window within Visual Studio.
Sample Code:
Describe "My-Function" {
Context "Parent Context" {
Mock Sample-Function {}
It "This test works" {
Assert-MockCalled Sample-Function
}
Context "Child Context" {
It "This test shows initially and executes, but disappears from Test Explorer after being run" {
Assert-MockCalled Sample-Function
}
}
}
}
Comments (3)
-
-
It appears this same behavior also occurs when using the -TestCases flag for an It block.
Sample Code:
Describe "My-Function" { Context "Context" { It "Given <Condition>, <Result>" -TestCases @( @{ Condition='Condition 1'; Result='Result 1' } @{ Condition='Condition 2'; Result='Result 2' } ) { param($Condition, $Result) Do-Something -Condition $Condition | Should -Be $Result } } }
In this case, when you save the tests file, Test Explorer shows the test "Given <Condition>, <Result>" under the context "Context". After running the tests, either through "Run All" or right clicking the context or describe and choosing "Run Selected Tests", the test is removed from Test Explorer and the total number of tests executed & count of test results omit the -TestCases test(s). As per the original issue, the Show output from: Tests window does have the full output, matching what happens if I run the test script manually with Invoke-Pester or F5.
-
The test adapter is pretty picky when it comes to the format of the test files. I'm sure it's not looking for nested context blocks nor the -TestCases parameter. Some work will need to be done to update it for these scenarios.
- Log in to comment
Apologies for omitting the version information from my original report:
At the time of my initial report, I did also have "Powershell Pester Testrunner 2017" installed but disabled; I have since uninstalled that extension completely and verified the issue still exists as described above. No other VS extensions are installed.