How do people enforce developers to write tests without a strict code coverage requirement?

Posted by martiangirlie@reddit | ExperiencedDevs | View on Reddit | 86 comments

At previous positions, I’ve always seen test writing enforced by meeting a percentage code coverage amount. The issue with that is that people will just write bad tests to get around the coverage requirement.

And we can’t rely on code reviews for people to enforce it either because… well we all know that relying on code reviews just falls to lowest-common-denominator in terms of quality.

Things I’ve considered:

- Add a comment on a PR through the CI that runs on PR creation, if a .ts file has been changed with no related .spec file change

- Add a comment on the PR through the CI if the coverage percentage has dropped, but don’t fail the build

- Include a checkbox in the PR template stating you added any tests needed

- Empower reviewer to reject a PR if no tests attached

The thing is, all of these options can just be circumvented by a guy who doesn’t feel like doing his job that day, and I don’t want a select few amount of people to have to be responsible for reviewing everything because they’re the only ones that care.

So I’m trying to find something that can be automated and enforced, but isn’t a hard limit on code coverage requirement.

And yes, I know that all of this is coming from a symptom that people should just agree on standards and do their jobs, but, especially in a corporate environment, you can’t expect that of people.