←back to thread

Delete tests

(andre.arko.net)
125 points mooreds | 5 comments | | HN request time: 0s | source
Show context
recursivedoubts ◴[] No.45071410[source]
One of the most important things you can do is move your tests up the abstraction layers and away from unit tests. For lack of a better term, to move to integration tests. End-to-end tests are often too far from the system to easily understand what's wrong when they break, and can overwhelm a development org. Integration tests (or whatever you want to call them) are often the sweet spot: not tied to a particular implementation, able to survive fairly significant system changes, but also easy enough to debug when they break.

https://grugbrain.dev/#grug-on-testing

replies(11): >>45071535 #>>45071726 #>>45071751 #>>45071944 #>>45072117 #>>45072123 #>>45072158 #>>45072321 #>>45072494 #>>45074365 #>>45080184 #
RHSeeger ◴[] No.45071726[source]
Integration tests and Unit tests are different tools; and each has their place and purpose. Using one "instead" of the other is a mistake.
replies(8): >>45072079 #>>45072176 #>>45072722 #>>45072873 #>>45073135 #>>45074394 #>>45080460 #>>45093392 #
s_ting765 ◴[] No.45072722[source]
Integration tests make unit tests absolutely redundant.
replies(2): >>45073253 #>>45073256 #
yakshaving_jgt ◴[] No.45073256[source]
No they don’t.

If you’re, for example, writing a web application, and you have an endpoint which parses some data from the request and then responds with the result of that computation, why the hell would you test the fine-grained behaviour of your parser by emulating HTTP requests against your server?

Testing the parsing function in isolation is orders of magnitude cheaper.

replies(1): >>45073388 #
s_ting765 ◴[] No.45073388[source]
Cheaper to run tests does not mean better. And your example does not test for real world behavior therefore the test is lower quality by definition.
replies(1): >>45078156 #
1. yakshaving_jgt ◴[] No.45078156{3}[source]
All else being equal, cheaper is absolutely better.

How does my example not test real world behaviour? I mean, I didn’t even provide any code here so what exactly are you imagining?

replies(1): >>45080732 #
2. s_ting765 ◴[] No.45080732[source]
Your example scenario avoided doing an end to end test for the data processing involving the parser instead opting for a unit test just for the parser.

We have developer sandboxes for this purpose so you don't have to guess the structure of the data you will receive from the actual server.

Also if all else was equal between multiple types of test, there wouldn't be need for comparison ala cheaper.

replies(1): >>45080872 #
3. yakshaving_jgt ◴[] No.45080872[source]
How do you know that? How do you know that I wouldn't write an integrated test which verifies that my parser is correctly integrated with my system?

The point is, there is typically more than one path through the logic of a parser. The cheapest way to test these paths is in isolation. If there are five paths you care about, you could write six integrated tests — one for each of the five paths you care about, and one to verify that your parser is correctly integrated with your system, or of course you could write five isolated tests (which are cheaper to write and cheaper to execute) and one integrated test.

So, five cheap tests and one more expensive test, or six more expensive tests.

> Also if all else was equal between multiple types of test, there wouldn't be need for comparison ala cheaper.

…What? I'm sorry, this is near enough unintelligible.

replies(1): >>45081165 #
4. s_ting765 ◴[] No.45081165{3}[source]
> How do you know that? How do you know that I wouldn't write an integrated test which verifies that my parser is correctly integrated with my system?

You already said so in your first argument: Unit tests are cheaper and better(than integrated tests I presume).

Am simply following your behavior pattern here.

> The point is, there is typically more than one path through the logic of a parser. The cheapest way to test these paths is in isolation. If there are five paths you care about, you could write six integrated tests — one for each of the five paths you care about, and one to verify that your parser is correctly integrated with your system, or of course you could write five isolated tests (which are cheaper to write and cheaper to execute) and one integrated test.

This is nonsense. A standard parser takes one input and does processing of this data to give an expected output. An integration test checks the parser does this one objective correctly. You have boiled down the 5 unit tests that don't test for anything *real into 1 integrated test that objectively gives better test data.

*code is not real until it does some business logic!

> Also if all else was equal between multiple types of test, there wouldn't be need for comparison ala cheaper.

> …What? I'm sorry, this is near enough unintelligible.

Maybe try to froth less when reading my comments, your brain might have some capacity left to understand comparitive adjectives.

replies(1): >>45081378 #
5. yakshaving_jgt ◴[] No.45081378{4}[source]
> This is nonsense. A standard parser takes one input and does processing of this data to give an expected output.

This appears to be the root of your confusion.

Here's a good example of a parser: https://entropicthoughts.com/parser-combinators-parsing-for-...

There are at least 16 paths through this function.

Not one.

16.