News for hackers. Stuff that matters.
Re:Test-Driven Development is Stupid by mabbo on Tuesday November 24, 2015 @08:15AM (#10620468)
> I am against writing unit tests in general, since experience shows that they actually prevent high-quality code from emerging from development

And he's lost me in his first sentence.

Unit testing, good unit testing at least, is not just about developing as it is about preventing regressions. A unit test that runs on every build ensure that something is true and that it stays true forever.

Re:Test-Driven Development is Stupid by alkonaut on Tuesday November 24, 2015 @08:21AM (#10620495)
This. I agree TDD can cause more harm than good in software design, but my test suite saves me from shipping several regressions per day that I would have otherwise not noticed.

Obviously if you are against testing in general you are against TDD (it's just testing taken to the extreme).

I thought he at least was going to say that he preferred higher level testing, to low level unit tests (which can be a fair point, you can find 90% of the issues with 10% of the test code if you accept that you can't always isolate the failure based on the test report). But no. He is against testing.

Re:Test-Driven Development is Stupid by akshatpradhan on Tuesday November 24, 2015 @11:14AM (#10621557)
How does TDD cause more harm than good in software design?
Re:Test-Driven Development is Stupid by alkonaut on Tuesday November 24, 2015 @01:55PM (#10622706)
You quickly get to the situation where the code is clean, concise modular and all those good words, but requires one more tweak/indirection only for the unit testing. the result is popularly called "Test induced design damage".
Re:Test-Driven Development is Stupid by eterm on Tuesday November 24, 2015 @08:41AM (#10620614)
I work somewhere without any unit tests at all, and he still lost me at that sentence.

If he thinks test driven development can produce horrible implementations then he's right, they can. But he's horribly wrong that the solution is to abandon unit testing.

Without unit tests developers begin to live in fear of parts of the code, and refuse to clean it up "in case it breaks something", and there's no way to verify those fears aren't founded.

Any refactoring job starts with annoying a lot of people by breaking things that previous worked and questions start to appear from people that "it used to work before" when some of those breakages slip through to the customer.

Refactoring becomes something to fear because "we'll have to retest everything" which is a large expense that cannot be afforded.

Re:Test-Driven Development is Stupid by pif on Tuesday November 24, 2015 @08:30AM (#10620548)
> Unit testing ... is not just about developing as it is about preventing regressions.

Absolutely this! Unit testing helps you during the dark years of maintenance phase, when you must fix a bug or add a new feature and you don't have the knowledge, nor the time, to build a full representation of the application in your head: you just touch as little code as possible to get the work done, and unit tests help to ensure that all the rest stays equal.

Re:Test-Driven Development is Stupid by anthonybsd on Tuesday November 24, 2015 @08:22AM (#10620504)
Indeed. I was ready to hear a rant about TDD with an open mind since I have some issues with it myself, but the opening line completely ruined it. He might as well rally against refactoring because unit tests are essential part of that too.
Re:Test-Driven Development is Stupid by zeveb on Tuesday November 24, 2015 @08:31AM (#10620560)
I think I see part of his point, though. By its nature, a unit test is (often, albeit not necessarily) tightly coupled with the thing it is testing--which means that anyone who changes the implementation must change the test, which increases the complexity of code changes.

I know that in my own work, the single most important thing for me is to be able to massively refactor, restructure and redesign my and others' code, as I'm working with it (this is probably why I like dynamic languages and macros so much, and probably why I benefit from static typing so much); anything which gets in the way of deleting, reorganising, clarifying, duplicating, altering, reducing and shifting code is going to slow me down and make the resulting code worse.

Perhaps, though, there is a middle ground: while the internals of a library must be free to mutate, the external interface ought not to change nearly as much. Perhaps all unit tests should be written to test the external interface, not the internal details. That might also help avoid the tests-which-test-that-the-code-does-what-it-does disease.

I do really appreciate tests, and they do help detect and prevent certain types of regressions.

Re:Test-Driven Development is Stupid by ed_blackburn on Tuesday November 24, 2015 @08:38AM (#10620599)
Which is why testing behaviour not implementation is so important. Admittedly this sounds easier than it is in practice. Personally I've found that in-memory coarse-grained tests more akin to integration tests, that test from the outside in are helpful and easier to maintain because they tend to be less concerned with the how. I can then choose to write finer-grained unit tests where appropraite
Re:Test-Driven Development is Stupid by mabbo on Thursday November 26, 2015 @06:59PM (#10635259)
Agreed! A code base I recently inherited (and exorcised) contained unit tests with roughly 90% coverage... And not a single assert. They didn't understand the idea of testing behavior, they just copied the implementation as tests.

I reduced 20,000 lines of tests to 5,000, and caught a dozen bugs.

Re:Test-Driven Development is Stupid by TeMPOraL on Tuesday November 24, 2015 @08:37AM (#10620595)
Regression tests are absolutely awesome, especially if written for nontrivial components which will later be modified or expanded.

Having worked with dynamic languages quite a bit, I found that iff your language has a decent REPL, so you can code iteratively, you don't need unit tests to drive your design. You perform those tests in REPL yourself, which helps you flesh out the design, but you don't have layers of code that'll make changing the design harder.

The way I personally work with Lisp is a mix of writing code in a file, compiling particular parts of it and playing around with it in REPL until I've figured out the right design - at which point I may as well start adding some tests around tricky places. The idea is to not burden yourself with permanent tests until you have your design figured out.

Re:Test-Driven Development is Stupid by davnicwil on Tuesday November 24, 2015 @11:24AM (#10621666)
> all unit tests should be written to test the external interface, not the internal details

Yes, this is the most useful approach to unit testing. If you have a functional interface which doesn't cause side effects, (i.e. state changes of any kind, external actions that can't really be effectively verified by test code, etc) then unit testing is very valuable and useful given you just test the interface using the simplest possible approach: a table of some inputs which should map to some outputs.

I'd go further and say you should always write the tests only after this interface has solidified. Test first makes sense only under either the assumption that your first design is always the best design, or that you are happy to spend the time to morph the tests, as well as the code when you realise your first design wasn't the best and have to iterate and tweak.

We all know from experience that the first assumption is never true. As for the second assumption, it may be true, but then the question becomes, well, why waste the time? You know those 'test-first' tests will just be rewritten anyway. Why not just write the tests last and save yourself a lot of wasted effort?

Re:Test-Driven Development is Stupid by reasonality on Tuesday November 24, 2015 @08:22AM (#10620503)
It depends what you're developing, and who you're developing with.

If you're developing something which must work 100% every time or else someone will die, then unit tests are a must.

If you're developing with people who break the build all the time, then unit tests are useful.

Unit tests that aren't 100% up to date with the code are worse than no unit tests.

Re:Test-Driven Development is Stupid by mabbo on Tuesday November 24, 2015 @08:25AM (#10620526)
On the teams I've work on, pushing code that doesn't build and pass all unit tests is grounds for mocking. I have an alias in my zshrc file called "safepush" that runs [clean command] && [build command] && [test command] && git push

If any piece doesn't succeed, the command stops. No push without unit tests passing.

Re:Test-Driven Development is Stupid by TeMPOraL on Tuesday November 24, 2015 @08:31AM (#10620566)
And, as the article points out nicely, this basically prevents people from refactoring their code. In any nontrivial codebase, when you have a lot of tests, then what would have been 15 minutes of work rearranging class structure turns into a whole day of rearranging test cases to fit the architecture again.
Re:Test-Driven Development is Stupid by mabbo on Tuesday November 24, 2015 @09:11AM (#10620744)
It can be, I won't entirely disagree. But it depends how highly coupled your unit tests are to the design.

Unit tests are a safety mechanism- you can easily bog yourself down with too many, tying things up in bad ways, or presuming a specific design. But do you really want to live with no safety at all?

The art, as I see it, lies in writing tests in such a way that you get the guarantees you need, the safety of not letting the next guy (or yourself) screw it all up during later changes while simultaneously not preventing you from doing needed refactoring.

It's a fun challenge.

Re:Test-Driven Development is Stupid by TeMPOraL on Tuesday November 24, 2015 @09:14AM (#10620760)
Exactly what you wrote. That's why I am generally for testing, but I don't buy into Test Driven Development.
Re:Test-Driven Development is Stupid by Freak_NL on Tuesday November 24, 2015 @08:54AM (#10620663)
In any halfway decent build your tests will run whenever you build the project, to prevent tests from ever getting outdated.

If any test fails, it is because you broke it just now, so you go in and see if your test is broken, or, as is often the case, your refactored code is breaking the expected behaviour of the tested code.

Re:Test-Driven Development is Stupid by emddudley on Tuesday November 24, 2015 @08:24AM (#10620517)
> Unit tests that aren't 100% up to date with the code are worse than no unit tests.

A bit of a tautology... broken code is broken. Unmaintained code, even unit tests, should be deleted.

Re:Test-Driven Development is Stupid by jerf on Tuesday November 24, 2015 @09:22AM (#10620811)
I'd be a lot less gung-ho about unit tests if all the tests I wrote always passed the first time I expected them to pass, and always stayed passing regardless of what changes people make to the code (including people who are not me). As neither of these things happens, I'm pretty gung-ho.