2.2 KiB
Executable file
2.2 KiB
Executable file
Do
- Name your files .tests.ps1
- Keep tests simple
- Test only what you need
- Reduce dependencies
- Be sure to tag your
Describe
blocks based on their purpose- Tag
CI
indicates that it will be run as part of the continuous integration process. These should be unit test like, and generally take less than a second. - Tag
Feature
indicates a higher level feature test (we will run these on a regular basis), for example, tests which go to remote resources, or test broader functionality - Tag
Scenario
indicates tests of integration with other features (these will be run on a less regular basis and test even broader functionality than feature tests.
- Tag
- Make sure that
Describe
/Context
/It
descriptions are useful- The error message should not be the place where you describe the test
- Use
Context
to group tests- Multiple
Context
blocks can help you group your test suite into logical sections
- Multiple
- Use
BeforeAll
/AfterAll
/BeforeEach
/AfterEach
instead of custom initiators - Prefer Try-Catch for expected errors and check $_.fullyQualifiedErrorId (don't use
should throw
) - Use
-testcases
when iterating over multipleIt
blocks - Use code coverage functionality where appropriate
- Use
Mock
functionality when you don't have your entire environment - Avoid free code in a
Describe
block- Use
[Before|After][Each|All]
see Free Code in a Describe block
- Use
- Avoid creating or using test files outside of TESTDRIVE:
- TESTDRIVE: has automatic clean-up
- Keep in mind that we are creating cross platform tests
- Avoid using the registry
- Avoid using COM
- Avoid being too specific about the count of a resource as these can change platform to platform
- ex: checking for the count of loaded format files, check rather for format data for a specific type
Don't
- Don't have too many evaluations in a single It block
- The first
Should
failure will stop that block
- The first
- Don't use
Should
outside of anIt
Block - Don't use the word "Error" or "Fail" to test a positive case
- ex: "Get-Childitem TESTDRIVE: shouldn't fail", rather "Get-ChildItem should be able to retrieve file listing from TESTDRIVE"