[Fixed]-Django โ€“ Writing unit tests with mocks

1๐Ÿ‘

If you want to test your models, you can hardly bypass the database, and yes indeed it can make the tests somewhat slower, even if using an in-memory SQLite db โ€“ which can lead to other problems FWIW since SQLite is not a transparant replacement for something like PostgreSQL.

But assuming whatever model or or other function / object / method you call in your views have their own unittest and you only want to check your views do the expected calls, mocking is viable strategy โ€“ actually probably saner than testing the results of the expected calls (which mostly turn your unittests into integration tests).

Leave a comment