Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion text/41_advanced_unit_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public class DuckPond extends Pond {
}
```

Let's set aside any issues one might have about how this code is written, and how it might be refactored to make it more testable. In this case, calling haveUltraFun() requires querying the database, which is called from a method from DuckPond's superclass. However, this also modifies the `_funLevel` variable, based on the value it received from the `retrieveUltraLevelFromDatabase()` call. The value of the variable `_funLevel` is going to depend both on that call to the database as well as how many times `haveFun()` and `haveUltraFun()` have been called. While it would be possible to just make a test double that returns specific values, adding in this behavior for a test which called multiple methods on a DuckPond object might add up to lots of extra work. Even worse, this work might have to be replicated in multiple tests.
Let's set aside any issues one might have about how this code is written, and how it might be refactored to make it more testable. In this case, calling `haveUltraFun()` requires querying the database, which is called from a method from DuckPond's superclass. However, this also modifies the `_funLevel` variable, based on the value it received from the `retrieveUltraLevelFromDatabase()` call. The value of the variable `_funLevel` is going to depend both on that call to the database as well as how many times `haveFun()` and `haveUltraFun()` have been called. While it would be possible to just make a test double that returns specific values, adding in this behavior for a test which called multiple methods on a DuckPond object might add up to lots of extra work. Even worse, this work might have to be replicated in multiple tests.

Using DuckPond as-is also means that every call to `haveUltraFun()` will result in a dramatic slowdown in tests. Remember that calls to the disk or network, since they make take an order of magnitude or longer in time than the test would take otherwise, are discouraged in unit testing.

Expand Down