Hacker News new | ask | show | jobs
by bite_victim 4006 days ago
Side rant:

I just cannot believe people praising 'Unit Test'-ing. Fellow programmers, how exactly do you unit test a method / function which draws something on the canvas for example? You assert that it doesn't break the code?!

I see some really talented people out there who write unit test as proof that their code works without issues, that it's awesome and it cooks eggs and bacon etc. They write such laughable tests you cannot even tell if they are joking or not. They test if the properties / attributes they are using in methods are set or not at various points in the setup routine. Or if some function is being called after an event is being triggered.

My point is this: unit testing can only cover such tiny, tiny scenarios and mostly logic stuff that it is almost useless in understanding what is going on in the big picture. Take for example a backbone application like the Media Manager in WordPress. Please tell me how somebody can even begin to unit test something like that.

Unit testing is a joke. And sometimes a massive time consuming joke with a fraction of a benefit considering the obvious limitation(s).

4 comments

WebKit does it like this: https://www.webkit.org/quality/testwriting.html

Adobes WebKit repository with layout tests: https://github.com/adobe/webkit/tree/master/LayoutTests

Example URLs from that repository:

https://github.com/adobe/webkit/blob/master/LayoutTests/css3...

https://github.com/adobe/webkit/blob/master/LayoutTests/css3...

https://github.com/adobe/webkit/blob/master/LayoutTests/css3...

Other browsers will have similar strategies.

I think this is essential for something with the complexity of a browser engine.

We've used image comparison tool, which produces pixel-wise diff with the expected image, exactly to verify these kind of things(we've been developing the rendering tool). In addition to this unit tests, combined with the coverage tools, allows you to find potential problems/crashes etc in your code. Different levels of testing are for different things, unit tests just one of the pieces in the equation.

Your point is just for some tiny tiny scenarios of the software you are working on.

You don't need to think about 'how could I write a unit test', you need to think about how could you improve the quality of the code, and unit tests are just one of your tools available to solve this problem.

That is pretty awesome that you've wrote a such a tool (although I can only imagine how long it took to create such a tool and how it affected the project time frame).

From a web developer's mind: the coll thing is that the tool can be further developed and taken to new directions. For example implement the capability to take snapshots of pages and see if they've changed in layout and notify the user of changes (pretty awesome for scrapping).

I totally agree, unit testing is such a small cog in the wheel of software quality that it is truly a shame how something like this takes all the scene.

> Fellow programmers, how exactly do you unit test a method / function which draws something on the canvas for example?

We don't. Canvas drawing routines are hopefully unit-tested already by their authors. We do write unit tests for calculations and logic to make sure that the values passed to some canvas function are as expected.

Some unit testing might be a joke, but not all unit testing. If you have small units-of-work they should be tested, or at least testable.

Integration testing often makes a lot more sense, though.

I believe I'm in the minority, but I think unit tests are nearly universally worthless - exceptions being those for well defined APIs (eg math). Good unit tests must have an independent oracle of truth or else you aren't testing anything. As a practical matter you should only write tests for code that materially impacts the business (or you are just wasting everyone's time ). Instead of writing regression or integration tests, which are hard (hence the need for testing), people absent mindedly write unit tests and point at code coverage.
I'll need concrete examples of good/bad tests to have any idea what you're talking about at this point. You say they're worthless but then say they're good for well-defined APIs, which is precisely what unit tests are for.