Live data from Hacker News

Poll: Do you test your code?

news.ycombinator.com

341–350 of 351 posts

Re: Poll: Do you test your code?

#341
Bottom line is: test code is code and you have to maintain it. If you write code that does not give you anything in return, or gives you more headaches than anything else, you wasted your time when you wrote it.

When you are writing any code, you should try to predict if what you will gain out of it will be worth it. In other words: evaluate the risks of anything you do in your life.

Re: Poll: Do you test your code?

#342

Bottom line is: test code is code and you have to maintain it. If you write code that does not give you anything in return, or gives you more headaches than anything else, you wasted your time when you wrote it. When you are writing any code, you should try to predict if what you will gain out of it will be worth it. In other words: evaluate the risks of anything you do in your life.

You shouldn't be proud of having 1 gazillion tests if all you do is rewrite/fix regressions on them.

Re: Poll: Do you test your code?

#343
I do simple output and performance testing. I md5 the output produced by our programs and test their run time, memory use, etc. so that when we change the code, we can verify the output is the same and performance is still OK. I try to do some unit testing too, but do not have time to do that as much as I'd like.

Re: Poll: Do you test your code?

#344

Why is there no "and also click" option for, "we are unhappy with the amount of testing we do, and are gradually adding more".

Really, downvoted? The survey seems predisposed to result in the conclusion that testing is a waste of time. My company finds it worthwhile enough that we are never happy with what we have. We could always write better tests, but we need more engineers than we can find to hire. So we are unhappy with the current situation, but are working to improve.

This is against HN guideline[1]:"Resist complaining about being downmodded. It never does any good, and it makes boring reading."

[1] http://ycombinator.com/newsguidelines.html

Re: Poll: Do you test your code?

#345

Earlier quoted context omitted.

New hacker news rule: if you haven't done at least 80% of what he's talking about, you can't dick-measuring-contest him. From scratch work is the easier part of programming.

I've done this before, friend. Starting from scratch is indeed easier. The point I was making was that he used unit tests to confirm his design (as a safety net) and not as a primary design tool.

Starting from scratch does not take into account all the growing pains the previous software hat that made it into the quagmire you have learned to hate.

Re: Poll: Do you test your code?

#346
post #276

Earlier quoted context omitted.

Then you didn't write good enough tests. I have deployed code that thousands of customers see without manually testing it. If my tests are green, I'm confident in deploying my code.

What tests your tests?

No one. That's how much faith I had in that test.

Re: Poll: Do you test your code?

#347

Earlier quoted context omitted.

Different levels of tests work here. I usually start with a very high-level test and then as I implement I do unit tests once I have a reasonably high confidence that the units are a good design. You should often be able to at least create an automated acceptance test for what you're doing (e.g., "as a user I want to click this button and see XYZ"). This is usually extremely decoupled from the implementation so it sh…

"If that doesn't seem doable you might be taking on a task that doesn't have a good set of requirements." Or it might have perfectly good requirements which are very hard to write automated tests for. Consider (for instance) a program to translate ABC music format to proper sheet music. It's easy to say the basic requirement: "The program has to accurately translate ABC format to legible and easy to read sheet music.…

Actually, I've written tests for half of that problem: Parsing ABC text into an internal format. That is a very clear problem and one just needs a representative set of input files (I now have around 500 of them -- the tests still run in less than a minute. It's true that I haven't been able to figure out a useful way to have an automated test for the drawing part. Here's my project: http://code.google.com/p/abcjs/

Re: Poll: Do you test your code?

#348

Earlier quoted context omitted.

I have never seen any half way decent developer write code for more then a few minutes without some sort of feedback, automated test suite or not. You are right that it will work more or less, but they work out the "less" part of that statement sooner rather then later. In my experience, that is a place you get to over time, only the people out of college write code for multiple hours straight, then debug everything…

> I have never seen any half way decent developer write code for more then a few minutes without some sort of feedback, automated test suite or not I do this all the time. Two reasons: 1. I can keep in "the flow" for an extended period of time. This is more important if the code is especially complicated. If I have to stop every few minutes to fix trivial errors, it's easy to forget important details of how everythin…

Didn't Knuth work on TeX for like 10 years?

Not all of us have 10 years to work on everything. ;)

Re: Poll: Do you test your code?

#349

Earlier quoted context omitted.

Please don't fix this with a technical solution. There is some reason that your developers aren't engaged in the work. Figure out why they don't care about working code or the user experience and fix that. If you plug the obvious holes, you won't have fixed your quality problems; you'll just shift them to the places where you won't notice them right away.

Please don't fix this with a technical solution. I can't agree more with wpietri above. There surely is a non-technical problem at play. That isn't to say that you shouldn't try to automate your babysitting, but if your need for babysitting is that severe, you have other problems.

Thank you both. I will not forget these pieces of advice.

Re: Poll: Do you test your code?

#350

Earlier quoted context omitted.

The very first thing I do when I take over a codebase is to write tests. Without tests, it's impossible to do maintenance work or add functionality in any sort of rigorous fashion--how can you know that your assumptions about how the code works are correct? How can you know that your trivial change didn't break something? Of course, tests don't actually tell you these things. But they can tell you that your assumptio…

Of course working on a code base without a majority test coverage is dodgy (and intellectually frustrating), but it's a necessary skill. I feel that it is unreasonable to expect that you will be able to pick up any code base and immediately write sufficient tests to get coverage on a majority of the code base. Speaking from my experience picking up old code bases, just being able to write isolated unit tests would re…

> I can't think of a single manager that I've worked for who would accept me saying, "it's going to take me 3-6 months of refactoring & building tests before I can start fixing bugs and providing enhancements."

I can't think of a single developer I've worked with who would try that approach.

When a bug is identified in a project with few-or-no tests, the approach that I usually see taken is to write some sort of large, slow integration test that exercises bug, then fix that. That allows you to prove that the bug exists and prove that the fix fixes it, at least for the documented case(s).

There's no reason to cover an entire legacy code base with tests if you're only changing a small portion of it.

Post reply on HN