Re:Ask HN: Concepts that clicked only years after you first ...
by closeparen on Sunday January 01, 2023 @12:13PM
(#34208222)
This is the way, but it’s tough to sell “we’re not going to unit test this part” in a professional setting where there are incentives to look more responsible than thou, directors are looking at unit test coverage reports, etc.
[ Parent
| on HN ]
Re:Ask HN: Concepts that clicked only years after you first ...
by sanderjd on Sunday January 01, 2023 @01:02PM
(#34208820)
Yeah I have no qualms about writing mostly-BS unit tests when the existing structure of a project makes it infeasible to write good ones. When in Rome! But when I'm starting from scratch or have a chance to do refactoring, I move toward the "functional core" approach as much as possible.
Re:Ask HN: Concepts that clicked only years after you first ...
by therealdrag0 on Monday January 02, 2023 @12:28PM
(#34220708)
You can still get code coverage points with broader tests.
I think it’s reasonable to disavow expecting single unit tests for nearly every method on every class with mock/boilerplate/copy-paste hell. However, I would still expect “local integration” unit tests that exercise broader chunks of code and keep code coverage up.
So it should be “I don’t need to write a new unit test for this because an existing unit test calls the method that calls this method without it being mocked and you can see it’s covered in the code coverage.”
Re:Ask HN: Concepts that clicked only years after you first ...
by closeparen on Monday January 02, 2023 @12:52PM
(#34221094)
Code coverage in Go is on a package level. A test that exercises a handler, controller, and repository can accrue coverage for at most one of them.
Re:Ask HN: Concepts that clicked only years after you first ...
by therealdrag0 on Monday January 02, 2023 @02:04PM
(#34222196)
Huh. I guess I’ll add that to the list of reasons I don’t like Go.