From the course: Agile Software Development: Clean Coding Practices

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Single assertion per test

Single assertion per test

From the course: Agile Software Development: Clean Coding Practices

Start my 1-month free trial

Single assertion per test

- [Instructor] Unit tests are a form of documentation for the code that it's testing. Each test, has the opportunity to communicate a small chunk of behavior that the system under test is expected to implement. Some test runners, even include the ability to output test names as documentation. When writing a unit test, an important thing to keep in mind, is that each test should contain exactly one assertion statement. Another way to state this, is that the unit test needs to have a single reason that it will fail. When an individual test contains multiple assertions, each one of them is a separate reason that the test can fail. Let's look at an example. Here's a small test that validates the functionality of a very simple class named Square, which has methods for computing the area and perimeter. This single test is testing the entire class. It's insuring that the length the attribute, contains the value that the Square…

Contents