You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`TestLimitedWorker` is missing unit test coverage for a couple of
branches in `LimitedWorker`. The reason why coverage isn't failing on
`main` is that `TestUserPurger` (the unit tests for `UserPurger`) calls
through to the real `LimitedWorker` code (doesn't mock it) and those
`UserPurger` unit tests were adding coverage to `LimitedWorker`.
In a future PR (#9049) I want to
make some changes to `TestUserPurger` that would cause them to no longer
cover certain branches of `LimitedWorker` and would cause a coverage
failure. It isn't `TestUserPurger`'s job to cover every line and branch
of `LimitedWorker`, that's `TestLimitedWorker`'s job, so I'm adding the
missing coverage to `TestLimitedWorker` now to prevent those coverage
failures in future.
This illustrates some of the risks of integrated tests:
* You make changes to the tests for one unit and that causes coverage
failures in *other* units, creating extra work to fix them. If we used
integrated tests frequently this could happen often.
* You can have missing unit tests and not know it because the lines and
branches are accidentally covered by the tests for *other* units.
* You might have a unit test that you think is covering a branch but
actually isn't going down that branch. Even though the test is wrong
it could still be passing. Missing coverage could save you but won't
if tests for *other* units are covering the branch that your broken
test is supposed to be covering.
In this case I wouldn't want `TestUserPurger` to mock `LimitedWorker`:
`UserPurger` contains lots of complex SQL queries that it executes
through `LimitedWorker` rather than directly. We want these queries to
be executed against the real DB so we can test that various objects are
deleted or not-deleted correctly.
I think the ideal solution might be for `TestUserPurger` to mock
`LimitedWorker`, intercept the SQLAlchemy queries that `UserPurger`
passes to the mock `LimitedWorker`, and for the _tests_ to then execute
those queries against the DB and assert that they return the right
results. But I'm not going to bite off that relatively major change
right now.
0 commit comments