Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Assert-ThrowAssertionException #22

Open
nohwnd opened this issue Aug 21, 2017 · 0 comments
Open

Add Assert-ThrowAssertionException #22

nohwnd opened this issue Aug 21, 2017 · 0 comments

Comments

@nohwnd
Copy link
Owner

nohwnd commented Aug 21, 2017

Assert-ThrowAssertionException is useful to test your own assertions or assertions that customize existing assertions:

function Assert-HasValidComputerName($Actual) {
    Assert-Match -Expected "^WKS\d{3}$" -Actual $Actual
}

To test such assertion customization we need to make sure it passes when correct data are provided, and fails when incorrect data are provided. To test the negative case we cannot just Assert-Throw because code could throw for tons of reasons. We need to match the exception explicitly, to simplify this setup, and avoid repeating the AssertionException typename over and over Assert-ThrowAssertionException should be added.

Customizing assertions and testing them is good practice for environment validation. See my reasoning here.

But the usage is not limited to that, even your unit tests can take advantage of moving the assertion language to higher level of abstraction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant