Live data from Hacker News

Ask HN: Do you write tests before the implementation?

news.ycombinator.com

311–320 of 329 posts

Re: Ask HN: Do you write tests before the implementation?

#312

My understanding is that tests are mostly supposed to increase iteration speed - the opposite of what most comments here suggest. > The change curve says that as the project runs, it becomes exponentially more expensive to make changes. > The fundamental assumption underlying XP is that it is possible to flatten the change curve enough to make evolutionary design work. > At the core are the practices of Testing, and…

Lots of people are writing tests as an end goal rather than a means to the “malleability” end goal. They end up writing tests that satisfy code coverage metrics, but are too closely tied to implementation.

Re: Ask HN: Do you write tests before the implementation?

#313
I use tests when I need to debug certain sections of my code. It's faster in the overall development process.

Also most of my tests revolve around business logic, where I need to test multiple versions of data.

The best advice I could give would be test cases around errors.

That's usually where most bugs are found, when something doesn't return what you expect.

Re: Ask HN: Do you write tests before the implementation?

#314

Earlier quoted context omitted.

I’ve had really good luck with react UI testing using Jest and React Testing Library and throwing in UI screenshot testing. At my previous job we eliminated selenium from our testing suite. We found that good UI unit and integration testing caught 99% of the bugs and the bugs that did make it through most likely wouldn’t have been caught by selenium so the added time wasn’t worth it.

IMO, snapshots, like Jest/React, are one of my favorite ways to test UIs. They require minimal effort and address the major points of testing a UI. Actual pixel "perfect" UI testing should still be done from time to time in a real browser. It's nearly impossible to properly capture some of the layout differences/bug that can come simply from a new browser version.

We ran screenshots and looked for a percentage same. Because 100% is almost impossible. Where it saved us over snapshots was we were using MUI and they introduced a breaking UI change that our snapshots didn’t catch the change. And the screenshot did because the menu was no longer hidden. But the code hadn’t changed.

Re: Ask HN: Do you write tests before the implementation?

#315
post #251

Nope. I pretty much always find it to be counterproductive. Most of programming happens in the exploration phase. That's the real problem solving. You're just trying things and seeing if some api gives you what you want or works as you might expect. You have no idea which functions to call or what classes to use, etc. If you write the tests before you do the exploration, you're saying you know what you're going to fi…

> You're just trying things and seeing if some api gives you what you want or works as you might expect. I don't do most of my programming this way, because mostly I'm writing new things, not gluing together existing APIs with a tiny amount of simple glue code. But when I do need to characterize existing APIs, I find that unit tests are a really helpful way to do it — especially in languages without REPLs, but even i…

Yeah, I'm all for unit tests when they're needed. They just aren't the first thing I'll write

Re: Ask HN: Do you write tests before the implementation?

#316

For maintenance & extension, yes. For new development, no. I've found that unless I have a solid architecture already (such as in a mature product), I end up massively modifying, or even entirely rewriting most of my tests as development goes on, which is a waste of time. Or even worse, I end up avoiding modifications to the architecture because I dread the amount of test rewrites I'll have to do.

What period do you consider swapping the definition from new development to extension?

Re: Ask HN: Do you write tests before the implementation?

#317

Earlier quoted context omitted.

"Effective tests" are a bit like the sufficiently smart compiler, or No true Scotsman fallacy. Tests either take a long time to run because they're integration tests in disguise, or they mock and stub module boundaries and are an impediment to design refactoring because lots of tests are invalidated. I tend towards favouring unit tests for leaf modules, especially those that get reused a lot, and fewer but rich (and…

Depending on your use of the term "unit" and "integration" (testing taxonomy is bad), I tend to do the opposite, but with the addition of acceptance (user feature testing) to tie the whole thing together. By this I mean that I unit test (as driven out by Discovery Testing i.e mocking collaborators) down the dependency graph until I hit a leaf node, which I will integration test against real external systems or black…

> (testing taxonomy is bad)

So true, it is terrible!

What I say is:

Unit tests - small tests that show the intent of one line of code or small set of lines, what the developer thought it was meant to do - can't prove correctness of an entire process

Integration tests - test one specific process works (login success, login fail, etc.) starts to prove correctness of one part of an application

Acceptance tests - larger, test that processes interact together and prove that multiple processes work

Production tests - (roll out to x users and monitor or something similar) - prove that the entire application works, in production.

Tests go from: Small to large, fast to slow, no risk to complete risk

Re: Ask HN: Do you write tests before the implementation?

#318

Earlier quoted context omitted.

Have you ever wondered why it became partisan to begin with? Lots of other issues are not partisan like "smoking causes cancer", everyone generally agrees that it does, even many years ago before the "science proved it". There is some science that is so obviously manipulated by power and money everyone knows something is wrong, but can't do anything about it.

I believe in this case the partisanship comes from less from the topic itself, but if you look into the proposed solutions, they all tend to shift money and power in a single direction and don't have much to offer in regards of actually changing the climate.

I suspect that's a product of anything that becomes political: whether it's climate change or border security, the incentives are more towards theater than results, creating an attack surface for economic exploitation.

At this point, I think the most efficient (and least corruptible) solution is a carbon tax + dividend [0], AKA a Pigovian tax [1]. It's not as though markets don't work; the problem is that externalities, ecological ones in particular, are not priced into the system, meaning we're just passing the bill to our descendants, at a phenomenally high interest rate.

https://en.wikipedia.org/wiki/Carbon_fee_and_dividend

https://en.wikipedia.org/wiki/Pigovian_tax

Re: Ask HN: Do you write tests before the implementation?

#319

Earlier quoted context omitted.

I accept the reality of global warming (I'm almost a single-issue voter on the subject), but I look at it from a Bayesian point of view: if we compared two universes, one where AGW was real, and one where the scientific consensus was mistaken (not exactly unprecedented), popular opinion would probably vary by no more than 1% between the two. Humans tend to start with moral intuitions and tribal affiliations, and then…

Have you ever wondered why it became partisan to begin with? Lots of other issues are not partisan like "smoking causes cancer", everyone generally agrees that it does, even many years ago before the "science proved it". There is some science that is so obviously manipulated by power and money everyone knows something is wrong, but can't do anything about it.

Yes, the perverse incentive of the oil lobby is transparently staggering. Even if one is charitable, that the lobbyists believe their own talking points, "it is difficult to get a man to understand something, when his salary depends upon his not understanding it".

That said, it didn't help the politicization of the climate for Al Gore to have become its face, thus associating its brand with Democrats, for all his pleading that "this issue is moral, not political". He meant well, but it was painfully naive.

Re: Ask HN: Do you write tests before the implementation?

#320

Earlier quoted context omitted.

I believe in this case the partisanship comes from less from the topic itself, but if you look into the proposed solutions, they all tend to shift money and power in a single direction and don't have much to offer in regards of actually changing the climate.

I suspect that's a product of anything that becomes political: whether it's climate change or border security, the incentives are more towards theater than results, creating an attack surface for economic exploitation. At this point, I think the most efficient (and least corruptible) solution is a carbon tax + dividend [0], AKA a Pigovian tax [1]. It's not as though markets don't work; the problem is that externaliti…

Do you think corrupt governments, that also happen to be the largest polluters in the world will participate with a carbon tax honestly and in good faith?
Post reply on HN