Hi All, I’m running into this issue where I’m casting a variable to [int] type, but unfortunately for me the data being fed is not always in a correct format to succeed 100%. I’ve created a basic test to illustrate my issue:
Describe "Test Non-Terminating Error" {
Context "Non-Terminating Error" {
It "Non-Terminating Error" {
[int]$Number = 'oc'
$Test = 'Test'
$obj = [PSCustomObject]@{
Number = $Number
Test = $test
}
$obj.Number | Should -BeNullOrEmpty
$obj.Test | Should -Be "Test"
}
}
}
When I run this test it always Fails and never processes any of the Assertions:
[-] Test Non-Terminating Error.Non-Terminating Error.Non-Terminating Error 21ms (20ms|1ms)I've already tried:FormatException: Input string was not in a correct format.PSInvalidCastException: Cannot convert value "oc" to type "System.Int32". Error: "Input string was not in a correct format."ArgumentTransformationMetadataException: Cannot convert value "oc" to type "System.Int32". Error: "Input string was not in a correct format."at , .\assets\_Test.Tests.ps1:11 Tests completed in 1.47s Tests Passed: 0, Failed: 1, Skipped: 0 NotRun: 0
- Configuring Pester Should ErrorPreference to 'Continue'
- Setting PowerShell Error Action Preference to 'SilentlyContinue' (
$ErrorActionPreference = 'SilentlyContinue') - Try/Catch doesn't catch because its Non-Terminating
I’m running Pester 5.0.3 on PowerShell 5.1
Please Help!