Hi, fellow sandboxers.
This is sort of a philosophical question, but I really wonder if you guys can suggest anything.
We're going to re-shape unit tests in our company and came up with the following plan. Just to explain the train of thought: imagine you need to test that a user can access a file he had previously uploaded.
Such scenario implies the system can
* establish a user account
* login a user
* upload a file for a user
* and, finally, read a file for a user
Eventually, all use cases form a hierarchy. On the top we have fundamental things: creating a new account, login, etc. Next go "less fundamental" things that rely on the previous ones, and so on.
If we build tests based on this hierarchy, we can reuse our "Write" routines in tests for the "Read" ones.
Again, we would
not use mocks to isolate Reads from Writes - instead, we'll be testing Writes
before and use them to fill in the data for Reads. (There will be some mocking, to restrict the Writes, but we'd be saving to the database anyway, and we'd use transactions to rollback after each test).
Immediate benefits:
- Writes could be easily refactored without affecting unit tests.
- We can get rid of duplicating "Write" business logic in "Read" tests - we'd just reuse our real business logic.
So, what can you say about the approach?
Thanks!