-
Notifications
You must be signed in to change notification settings - Fork 205
Conversation
Review status: 0 of 2 files reviewed at latest revision, 4 unresolved discussions. Tests.Template/unit_template1.ps1, line 2 [r1] (raw file):
SYNOPSIS Tests.Template/unit_template1.ps1, line 3 [r1] (raw file):
Indent text below the help keywords Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
These should be camel case ($script:dscModuleName, $script:dscResourceName) Tests.Template/unit_template1.ps1, line 39 [r1] (raw file):
We should use Pester's BeforeAll instead of putting init code here. Which means the template would look more like this:
} Though Pester may start complaining about script variables used in the Describe block that are declared outside the Describe block then. Comments from Reviewable |
Review status: 0 of 2 files reviewed at latest revision, 6 unresolved discussions. Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
What are those 2 variables used for? They are nor referenced by the template. Tests.Template/unit_template1.ps1, line 25 [r1] (raw file):
Do we need the 2 checks here? Isn't the check for TestHelper.psm1 enough? Tests.Template/unit_template1.ps1, line 39 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 8 unresolved discussions. Tests.Template/unit_template1.ps1, line 47 [r1] (raw file):
We should probably wrap this in a function (BeforeAllTests?), which would make it easier to move this to a BeforeAll block when support for nested Describes are available. Similar comment for the code in finally. Tests.Template/unit_template1.ps1, line 82 [r1] (raw file):
"safely" Comments from Reviewable |
Review status: 0 of 2 files reviewed at latest revision, 9 unresolved discussions. Tests.Template/unit_template2.ps1, line 66 [r1] (raw file):
Context is more appropriate for this.
Comments from Reviewable |
Review status: 0 of 2 files reviewed at latest revision, 9 unresolved discussions. Tests.Template/unit_template2.ps1, line 66 [r1] (raw file):
oh! and It should use 'Should' It 'The Get method should return something' Comments from Reviewable |
What are the differences between the templates in that case? What is a small resource? Reviewed 3 of 3 files at r1. Tests.Template/unit_template2.ps1, line 66 [r1] (raw file):
|
Review status: all files reviewed at latest revision, 9 unresolved discussions. Tests.Template/unit_template2.ps1, line 66 [r1] (raw file): Agree on use of BeforeAll wrapping this code:
Comments from Reviewable |
Review status: 0 of 2 files reviewed at latest revision, 9 unresolved discussions. Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
|
@johlju I agree that it would be easier to use the same template, however there are different styles of writing unit tests and some are much better than others depending on the nature of the functions in the resource |
Review status: 0 of 2 files reviewed at latest revision, 9 unresolved discussions. Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 9 unresolved discussions. Tests.Template/unit_template1.ps1, line 2 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 9 unresolved discussions. Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 9 unresolved discussions. Tests.Template/unit_template1.ps1, line 39 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 9 unresolved discussions. Tests.Template/unit_template2.ps1, line 100 [r3] (raw file):
Shoudl use Comments from Reviewable |
Review status: 0 of 2 files reviewed at latest revision, 10 unresolved discussions. Tests.Template/unit_template1.ps1, line 43 [r3] (raw file):
It's not obvious that this function should be used to add init code. When your read it it feels like a function for the initialization of the pester tests for the template. Unless you read to the bottom. Comments from Reviewable |
Review status: 0 of 2 files reviewed at latest revision, 10 unresolved discussions. Tests.Template/unit_template1.ps1, line 43 [r3] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 17 unresolved discussions. Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
|
I'm not sure we really need two unit test templates... unit_template2 is a slightly more advanced version of unit_template1, but 80% of it is the same, so perhaps we could do with just this one? We could add additional region which would contain 'describe' structure from unit_template1 as an alternative approach and would be commented out by default. Single template would be easier to maintain and cause less confusion. Currently it's not even clear which template should be used, as the only distinction is "large" vs "not large" module which can be very subjective. |
Review status: 0 of 2 files reviewed at latest revision, 17 unresolved discussions. Tests.Template/unit_template1.ps1, line 25 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 14 unresolved discussions. Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 14 unresolved discussions. Tests.Template/unit_template1.ps1, line 43 [r3] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 14 unresolved discussions. Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 14 unresolved discussions. Tests.Template/unit_template1.ps1, line 43 [r3] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 13 unresolved discussions. Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 13 unresolved discussions. Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 13 unresolved discussions. Tests.Template/unit_template1.ps1, line 18 [r1] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 12 unresolved discussions. Tests.Template/unit_template1.ps1, line 43 [r3] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 13 unresolved discussions. Tests.Template/unit_template2.ps1, line 3 [r3] (raw file):
|
Reviewed 1 of 3 files at r1, 2 of 2 files at r4. Tests.Template/unit_template1.ps1, line 43 [r3] (raw file):
|
Review status: all files reviewed at latest revision, 14 unresolved discussions. Tests.Template/unit_template1.ps1, line 43 [r3] (raw file):
|
Tests.Template/unit_template2.ps1, line 3 [r3] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 14 unresolved discussions. Tests.Template/unit_template2.ps1, line 3 [r3] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 14 unresolved discussions. Tests.Template/unit_template2.ps1, line 3 [r3] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 14 unresolved discussions. Tests.Template/unit_template2.ps1, line 3 [r3] (raw file):
|
Tests.Template/unit_template2.ps1, line 3 [r3] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 14 unresolved discussions. Tests.Template/unit_template2.ps1, line 3 [r3] (raw file):
|
Tests.Template/unit_template2.ps1, line 3 [r3] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 15 unresolved discussions. Tests.Template/unit_template.ps1, line 18 [r1] (raw file):
|
@kwirkykat - can you take a look at the most recent changes I made? |
I like this setup with the patterns in test guidelines much better 👍 Reviewed 1 of 3 files at r1, 2 of 3 files at r5, 1 of 2 files at r6. TestsGuidelines.md, line 93 [r6] (raw file):
All these region definitions are not needed. Can this be more in the style of documentation rather than code comments? Pattern 1: Describe 'Get-TargetResource' {
# TODO: Complete Get-TargetResource Tests...
}
Describe 'Set-TargetResource' {
# TODO: Complete Set-TargetResource Tests...
}
Describe 'Test-TargetResource' {
# TODO: Complete Test-TargetResource Tests...
} Pattern 2: Describe 'The system is not in the desired state' {
#TODO: Mock cmdlets here that represent the system not being in the desired state
#TODO: Create a set of parameters to test your get/set/test methods in this state
$testParameters = @{
Property1 = 'value'
Property2 = 'value'
}
#TODO: Update the assertions below to align with the expected results of this state
It 'Should return something' {
Get-TargetResource @testParameters | Should Be 'something'
}
It 'Should return false' {
Test-TargetResource @testParameters | Should be $false
}
It 'Should call Demo-CmdletName' {
Set-TargetResource @testParameters
#TODO: Assert that the appropriate cmdlets were called
Assert-MockCalled Demo-CmdletName
}
}
or
```powershell
Describe 'The system is in the desired state' {
#TODO: Mock cmdlets here that represent the system being in the desired state
#TODO: Create a set of parameters to test your get/set/test methods in this state
$testParameters = @{
Property1 = 'value'
Property2 = 'value'
}
#TODO: Update the assertions below to align with the expected results of this state
It 'Should return something' {
Get-TargetResource @testParameters | Should Be 'something'
}
It 'Should return true' {
Test-TargetResource @testParameters | Should be $true
}
} Tests.Template/unit_template.ps1, line 51 [r5] (raw file):
|
Review status: 1 of 2 files reviewed at latest revision, 13 unresolved discussions. Tests.Template/unit_template2.ps1, line 3 [r3] (raw file):
|
Review status: 0 of 2 files reviewed at latest revision, 13 unresolved discussions. TestsGuidelines.md, line 93 [r6] (raw file):
|
Reviewed 1 of 3 files at r5, 1 of 2 files at r6, 2 of 2 files at r7. Tests.Template/unit_template.ps1, line 27 [r3] (raw file):
|
Opening this PR so that we can get feedback on our unit test templates. What do you think about having 2-3 templates available? Are there any other major/minor changes that you think they need?
This change is