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.

Keep your tests isolated

Keep your tests isolated

From the course: Agile Software Development: Clean Coding Practices

Start my 1-month free trial

Keep your tests isolated

- [Instructor] When writing unit tests, it's important to make sure that each test can be run in complete isolation of the others. Failing to do this can cause unexpected test failures, and hunting for the causes of these failures can cost you valuable time. Here are a couple of tests that can illustrate this problem for us. The first test ensures that the add method is working correctly, and the second test ensures the subtract method is working correctly. Before we dive in any further, we need to build this project. Now let's run the tests using the test runner that's built into the IDE. And they are passing. But what happens if we run just the subtract test? We can see that the subtract test is failing when we run it by itself. If we look at the subtract test more closely, we can see that it's depending on the add test to run and set the calculator's value to four before it runs. To fix this, let's add a line…

Contents