An assertion checks whether an observed result matches the expected condition. It turns execution into verification: a test must confirm every relevant outcome, not merely traverse code paths. section 1.3
Use assertions to distinguish exercised code from tested behavior:
- Assert explicit outcomes, such as a method's return value. section 1.3
- Verify implicit outcomes too, such as state recorded in a property. section 1.3
- Treat assertion-free tests as useless: they execute code but verify nothing and always pass. section 1.3
- Use coverage as a negative indicator, not as proof that assertions establish test quality. section 1.6
Checking an observable result
A test calls IsStringLong("abc"), stores the result, and asserts that it equals false. If the method also updates WasLastStringLong, a complete test checks that second outcome rather than relying on coverage alone. section 1.3
Listing 1.3. A test with no assertions always passes.
public void Test()
{
bool result1 = IsStringLong("abc"); #1
bool result2 = IsStringLong("abcdef"); #2
}
Compare a test that invokes two inputs without assertions with assertion-based tests that can fail when behavior changes. section 1.3














