4 ms·
To quote Kent Beck of Extreme Programming fame [1]: --- start quote --- I get paid for code that works, not for tests, so my philosophy is to test as little a
by troupo 3y ago
To quote Kent Beck of Extreme Programming fame [1]:
--- start quote ---
I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence
--- end quote ---
In my opinion, TDD as proposed by testing zealots is harmful. Instead of testing a unit of work testing frameworks and methodologies all but force you to test units of code, and that is not the same thing.
E.g., if your code responds with a list of items from a database, you should test that. Instead, people test the controller in isolation (mocking everything), the transforming function in isolation (mocking everything), the database layer in isolation (mocking everything)...
No. You have to test that your code, when called, returns a list of items. If you can't have the database, mock that, and only that. Boom, you have 1500% fewer tests, with the same coverage, and an actually increased level of confidence.
[1] https://stackoverflow.com/a/153565 https://stackoverflow.com/a/153565
- tetha 3y agoYeah, I've found I'm starting to write fewer, and coarser tests and it is good for the code base. You can always augment them with bugs later on. And if you can isolate the main logic of a system into small components extended by addition over modification, even better. In most of the small systems we're developing at work, I tend to have 2 groups of tests: One testcontainer driven test testing the actual database layer. These tests are very simple and small - migrate the database, call insert a few times, load objects back and compare them. Nothing more. And the other tests are usually more of the nature of "Given these elements in the database, expect that output for a REST call", augmented with a few tests of some fiddly functions. The other thing I meant occured for example in a stream processor, which needed to apply different transformations to incoming messages for normalization, default values, precomputations and so on. Here we reached a point of confidence where each of these processors was tested as a stream to stream mapping in isolation. It was pretty and it worked wonderfully and without issues. If you can achieve this kind of system of pretty much functional components and extension by addition, that's very much a pinnacle of testability.
- Supermancho 3y ago> You have to test that your code, when called, returns a list of items. What do you do when the list it wrong? (eg, not transformed/serialized/sanitized/whatever) Sometimes, manual tests show it's not the expected/correct data from the first run; or later someone adds a line of code (adds a period to a random row). The test runs happy, even thought the data is now incorrect/unexpected. Moving something that can be automated with mocks, to manual processes, is a bad tradeoff.
- troupo 3y ago> What do you do when the list it wrong? (eg, not transformed/serialized/sanitized/whatever) What do you do when that happens with "regular" unit tests that test every single piece of code in isolation? You fix it. > Moving something that can be automated with mocks, to manual processes Who said anything about manual processes?
- Supermancho 3y ago> Who said anything about manual processes? It's either automated or manual.
- troupo 3y agoWhat is? Where in my comment did I say anything about manual process? Please re-read what I wrote.
- Supermancho 3y ago> What do you do when that happens with "regular" unit tests that test every single piece of code in isolation? > You fix it. If you don't find it via an automated means, it's via a manual means. The implicit assumption is that the error is found, regardless of where that happens, in dev, test, prod, or your env de-jour. Good luck with whatever.