Live data from Hacker News

Composable Tests

newsletter.kentbeck.com

61–67 of 67 posts

Re: Composable Tests

#61

Earlier quoted context omitted.

> The isolation comes from the test implementation not the framework. There isn’t any framework out there that can guarantee/give you isolation. I'm not sure what you mean by that. All the frameworks I ever used were designed with test isolation as the primary design goal. Even when you set shared test fixtures and setup/teardown code, all they provide is a way to share code across tests, which are by themselves inde…

All I mean that there is no way for a framework to prevent your tests from interfering with each other, or to solve isolation for you. It’s the implementation of each test that is responsible for its isolation. Every time you write or make changes to your tests. You have to think, can they mess with each other.

> All I mean that there is no way for a framework to prevent your tests from interfering with each other, or to solve isolation for you.

What? By design that's exactly how virtually all test frameworks are designed to work.

> It's the implementation of each test that is responsible for its isolation. Every time you write or make changes to your tests. You have to think, can they mess with each other.

Nonsense. I've been writing unit tests for years in multiple programming languages and using multiple frameworks, and not once did I stumbled upon any scenario whatsoever where I had to be mindful about isolating tests. Because that was assured and a given from the very start.

I wonder what kind of convoluted mess you are doing with your tests.

Re: Composable Tests

#62

Earlier quoted context omitted.

All I mean that there is no way for a framework to prevent your tests from interfering with each other, or to solve isolation for you. It’s the implementation of each test that is responsible for its isolation. Every time you write or make changes to your tests. You have to think, can they mess with each other.

> All I mean that there is no way for a framework to prevent your tests from interfering with each other, or to solve isolation for you. What? By design that's exactly how virtually all test frameworks are designed to work. > It's the implementation of each test that is responsible for its isolation. Every time you write or make changes to your tests. You have to think, can they mess with each other. Nonsense. I've b…

You’ve never ever had to be mindful about isolation of tests? Also, Unit tests aren’t the only tests that exist.

You say assured? You think it’s impossible to write 2 tests that interact each other?

All you gotta do is google “test isolation”. But if you want to pretend it’s not a thing the I have no idea what to tell you?

Here’s one example since junit came up

https://martinfowler.com/bliki/JunitNewInstance.html

Re: Composable Tests

#63
post #54

Earlier quoted context omitted.

> While I don't doubt the veracity of your report, I don't think this is an efficient testing strategy. The marginal cost of running the tests like that was very small, and bugs were found. The cost per found bug seemed very reasonable. Every test failure in this strategy indicates a bug. (This was the standard compliance test suite for Common Lisp, btw.)

Now imagine someone who needs to test something on eg. P6e-GB200 series VM in EC2 (this is one of the newest Nvidia accelerator models: GB200 multiplied by something like 60 iirc). I don't know what the price is and I'm not even sure you can just create this kind of a VM with any regular account, but I'm sure you can imagine a price of running such a test. The price doesn't have to be the limiting factor. It may be t…

If these tests are being run just once, the cost of creating them will likely vastly outweigh the cost of running them.

If they are run more than once, they can be reordered randomly each time at zero marginal cost.

Re: Composable Tests

#64

Earlier quoted context omitted.

> All I mean that there is no way for a framework to prevent your tests from interfering with each other, or to solve isolation for you. What? By design that's exactly how virtually all test frameworks are designed to work. > It's the implementation of each test that is responsible for its isolation. Every time you write or make changes to your tests. You have to think, can they mess with each other. Nonsense. I've b…

You’ve never ever had to be mindful about isolation of tests? Also, Unit tests aren’t the only tests that exist. You say assured? You think it’s impossible to write 2 tests that interact each other? All you gotta do is google “test isolation”. But if you want to pretend it’s not a thing the I have no idea what to tell you? Here’s one example since junit came up https://martinfowler.com/bliki/JunitNewInstance.html

> You’ve never ever had to be mindful about isolation of tests? Also, Unit tests aren’t the only tests that exist.

No. Frameworks take care of it out of the box, and you need to go way out of your way to mess that up.

> Also, Unit tests aren’t the only tests that exist.

True, but that's immaterial to the discussion.

> All you gotta do is google “test isolation”.

Yes,and if you follow your own recommendations you will eventually discover that virtually all testing frameworks are explicitly designed with test isolation in mind, to the point that you need to go way out of your way to design custom test fixtures to share context across test runs.

> Here’s one example since junit came up

I seriously do not think you even read the article you are citing. Did you even bothered to open the link?

Re: Composable Tests

#65

Earlier quoted context omitted.

In JUnit, tests run sequentially in a single thread by default [1]. Parallel execution must be explicitly enabled. When enabled, JUnit uses a fork-join thread pool, so tests may run concurrently on different worker threads. Because these threads are reused, a ThreadLocal value left behind by one test could be visible to a later test that happens to run on the same thread. Setup and teardown methods can be used to cre…

> Parallel execution must be explicitly enabled. When enabled, JUnit uses a fork-join thread pool, so tests may run concurrently on different worker threads. Because these threads are reused, a ThreadLocal value left behind by one test could be visible to a later test that happens to run on the same thread. I don't understand your comment. JUnit docs describe parallel execution as an experimental feature that still h…

I disagree so hard with the notion that isolation is somehow done for you, that I don't even know how to begin arguing.

I'll admit to starting this confusion by reading what I thought would be written, not what was actually there. TFA does phrase it to my satisfaction that the test is isolated. I assumed when reading it that Kent thought he had isolation but did not. By analogies: a naive programmer does not perceive the existence of race conditions; a naive web app developer doesn't perceive the existence of CAP; a naive backend engineer thinks they have full ACID guarantees when they're only guaranteed READ_COMMITTED. I thought I was reading another writer just wishing isolation into existence through ignorance.

(So I accidentally straw-manned Kent's argument, but maybe that's not such a problem, because it seems you're OK with the straw man version?)

Anyway, maybe a question moves things forward.

JUnit's been around for decades. Every developer has had multicore dev machines for decades. Why would parallel execution not be the default, or a simple toggle that everyone would turn on immediately?

Re: Composable Tests

#66

Earlier quoted context omitted.

You’ve never ever had to be mindful about isolation of tests? Also, Unit tests aren’t the only tests that exist. You say assured? You think it’s impossible to write 2 tests that interact each other? All you gotta do is google “test isolation”. But if you want to pretend it’s not a thing the I have no idea what to tell you? Here’s one example since junit came up https://martinfowler.com/bliki/JunitNewInstance.html

> You’ve never ever had to be mindful about isolation of tests? Also, Unit tests aren’t the only tests that exist. No. Frameworks take care of it out of the box, and you need to go way out of your way to mess that up. > Also, Unit tests aren’t the only tests that exist. True, but that's immaterial to the discussion. > All you gotta do is google “test isolation”. Yes,and if you follow your own recommendations you will…

¯\_(ツ)_/¯

You can believe whatever you want to believe. Or maybe you live in a magical world where all your tests are pure and side effects nor IO exist.

In the other thread you think running tests in parallel doesn't count because it has documented gotchas...

Re: Composable Tests

#67
post #63

Earlier quoted context omitted.

Now imagine someone who needs to test something on eg. P6e-GB200 series VM in EC2 (this is one of the newest Nvidia accelerator models: GB200 multiplied by something like 60 iirc). I don't know what the price is and I'm not even sure you can just create this kind of a VM with any regular account, but I'm sure you can imagine a price of running such a test. The price doesn't have to be the limiting factor. It may be t…

If these tests are being run just once, the cost of creating them will likely vastly outweigh the cost of running them. If they are run more than once, they can be reordered randomly each time at zero marginal cost.

This is not at all how it works.

But you missed the important distinction: random is bad because it repeats unnecessarily. One of the typically used examples in statistics 101 class to drive attention to this fact is the question posed to students to guess, without actually doing any math: what is the chance of two people in a room with (however many students are there in the class) to have a birthday on the same day?

People consistently estimate the chance significantly lower than what it actually is. And this error is supposed to encourage students to dedicate more attention to the subject because they will have found their intuition to be so woefully inadequate.

See this for the exact math: https://en.wikipedia.org/wiki/Birthday_problem .

* * *

Now, if you are interested in economics of writing tests and running them (but you don't have to be, unless it's your job):

First of all, for this problem, it doesn't matter how much it costs to write the tests. We are talking about the strategy to cover more feature combinations in the test, so, no matter how much it costs to write a test, the cost (per test) will be the same regardless of the strategy chosen. The combination is where the difference will manifest itself.

Second, tests are normally written by salaried employees. This makes the cost of writing an individual test very difficult to divine (and even if you could, it would be a useless metric). It's difficult to calculate because a lot of factors that contribute to writing a test happen in aggregates (eg. the tester needs to explore and familiarize themselves with the system before writing a test, but this effort contributes to multiple tests). Salaried employees are paid a fixed amount regardless of the intensity of work: if they produce one, ten or a hundred tests per month, the salary is the same. Tests can be vastly different in scope and in an effort necessary to implement them, however the effort necessary to implement a test isn't indicative of the value of the test (it's possible that a very simple test will be very effective at detecting problems where a very complex test isn't and the other way around).

All this said, suppose you did come up with a way of calculating the cost of writing an individual test: it still doesn't help you to estimate the cost of testing the product, it doesn't even move the needle on this question. It changes nothing about your QA department budget. It changes nothing about delivery schedule. It's just a number you can marvel at in your spare time...

Post reply on HN