HackerTrans
TopNewTrendsCommentsPastAskShowJobs

langager

no profile record

comments

langager
·4 jaar geleden·discuss
I really enjoyed this article and spoke to a lot of the lived experience I've had in over abstracted codebases that had tests incredibly coupled to implementation.

I think this title could maybe be rewritten as "Unit Testing that Requires Mocks is Overrated".

Unit testing something that has no (or very simple) dependencies is great. For example: - some kind of encryption that takes in a string as a key - serialization that expects the same output as the input passed in - a transform function that takes in one type and expects a different type out

As soon as you rely on a DB, file system, etc... you're probably better off with an e2e test.

At the end of the day, it comes down to data contracts. This could be the functions a package exposes or the GQL/REST/gRPC/whatever API. That is the most important thing to not break the behavior of. Write good tests that target the external facing data contracts and treat implementation like a black box and you'll be empowered to do the important things that tests should enable like refactoring, reworking abstractions that may have made sense at one point, but no longer do, and let your codebase evolve as you learn.

Tests that are a barrier to reworking internal abstractions are not good tests.