-
Notifications
You must be signed in to change notification settings - Fork 52
Unit Tests
Unit tests are provided and can be used with the Pester framework. Please visit the Pester Github page and the Pester Wiki for information about installing and setting it up. There is also a detailed walkthrough provided by The Scripting Guys.
Once Pester is installed, navigate to the directory and run Invoke-Pester
You should see output similar to this:
Describing Add-IniComment
Context Alias
[+] Add-IniComment alias should exist 111ms
Describing Get-IniContent
Context Alias
[+] Get-IniContent alias should exist 83ms
Describing Out-IniFile
Context Alias
[+] Out-IniFile alias should exist 111ms
Describing PsIni manifest
[+] has a valid manifest 67ms
[+] has a valid name in the manifest 7ms
[+] has a valid guid in the manifest 6ms
[+] has a valid version in the manifest 8ms
Describing PsIni functionality
Context Load Module
[+] loads the module 85ms
Context Writing INI
[+] creates a file 52ms
[+] content matches expected value 16ms
... etc
Describing Set-IniContent
Context Alias
[+] Set-IniContent alias should exist 70ms
Tests completed in 1.22s
Passed: 28 Failed: 0 Skipped: 0 Pending: 0 Inconclusive: 0
##Adding New Tests Tests are provided for checking the module manifest, core functionality of each function, and global style rules. To add or change tests, edit the PsIni.Tests file in the Tests folder. Individual files for each external function are also used, but those are mainly for setting paths and testing the aliases.
One of the first things done in the tests is to run Import-Module -Force on the local PsIni code, so any changes that need to be tested are loaded preemptively.
For each function test in PsIni.Tests, the following template is used: a temporary ini is created, the function being tested is used on the test data, then one or more assertions validate that the changes made resulted in the expected output. An example that tests updating an ini is provided below:
Context "Updating INI Content" {
# act
$content = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase)
$content["Category1"] = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase)
$content["Category1"]["Key1"] = "Value1"
$content["Category1"]["Key2"] = "Value2"
$content["Category2"] = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase)
$content["Category2"]["Key3"] = "Value3"
$content["Category2"]["Key4"] = "Value4"
$content | Set-IniContent -Sections 'Category1' -NameValuePairs @{'Key1'='NewValue1'}
# assert
It "updates INI content with the new value" {
$content['Category1']['Key1'] | Should Be 'NewValue1'
}
}