-
Notifications
You must be signed in to change notification settings - Fork 732
Capture design guidelines, principles and patterns #1340
Copy link
Copy link
Closed
Labels
Description
- High-level principles such as written down in Open up
OccurenceConstraintfor usage in custom assertion extensions #1281 (comment) - Behavioral patterns such as how to deal with
nullarguments - When to return
AndWhichConstraintvsAndConstraint. - When to use
FailWithvs throwing a normal .NET exception type - Prefer "Did not expect something to be" over "Expected something not to be"
- Decisions (like a poor mans Architecture Design Log) such as why we target certain frameworks
- When using
AndWhichConstraint<..., T>theTelement must be fetched in way resilient to thatFailWithdon't throw immediately when encapsulated in a customAssertionScope. - Assertion class over non-sealed classes or interfaces should probably be generic in type to avoid loosing type information.
E.g instead ofMyClassAssertionsthenMyClassAssertions<T> where T : MyClass - Be aware that an assertion might be wrapped in an
AssertionScopesoFailWithdoes not halts execution and extra precautions must be taken to avoid e.g. enNullReferenceExceptionafter verifying thatSubject is not null - Don't use
predicate.Bodyto format a predicate in a failure message. Just pass the predicate toFailWithand let thePredicateLambdaExpressionValueFormatterhandle formatting it properly - Naming and grouping guidelines (based on this post)
- Group tests for the same API using a nested class such as in NullableNumericSpecs so you don't have to repeat the API name in the name of the test
- Avoid the use of
WhenandShouldin test names and use concise names likeExclusion_of_missing_members_works_with_mapping
- When writing parameterized tests prefer using
[InlineData], unless:- the values are not compile-time constants, or
- there is a good reason to share the parameters between multiple tests.
- Don't use
Should().NotThrowin the assert.
Code style
- String formatting should use Invariant culture when formatting non-strings.
- Lines should not be wider than 130 characters.
- Prefer
is nullandis not nullover!=/== null
Reactions are currently unavailable