Tag Archives: unit test

Use “get” methods to help writing more testable code

Imagine you have the following code

If you were writing unit test against do_something(), you would need to do some complex mocking on User.objects.filter() to return some mock up data. But this can be easily prevented by refactoring into a separate get_users() method as below:

This way, you can just mock get_users() to… Read More »