News for hackers. Stuff that matters.
Re:Cover your PHP legacy code with 1000 unit tests in just f... by waps on Thursday September 19, 2013 @07:57AM (#6411061)
This is why unit tests suck. They are but a simple exercise in basic code interpretation. A computer can easily do it.

What you want to test is the interface of your module to the rest of the application and whether it satisfies the published contract, and preferably if it handles weird cases correctly.

Those tests cannot be done by a tool.

Re:Cover your PHP legacy code with 1000 unit tests in just f... by mercurial on Thursday September 19, 2013 @09:11AM (#6411360)
> What you want to test is the interface of your module to the rest of the application and whether it satisfies the published contract, and preferably if it handles weird cases correctly.

I don't know what's a "module". If a module is a "small unit of code" (eg, a class), that's usually what you cover in your unit test.

Re:Cover your PHP legacy code with 1000 unit tests in just f... by lotsofcows on Thursday September 19, 2013 @09:16AM (#6411384)
http://en.wikipedia.org/wiki/Unit_testing

You're criticising unit test for things that unit tests don't do.

I hate apples. They don't taste like pears.

Re:Cover your PHP legacy code with 1000 unit tests in just f... by waps on Friday September 20, 2013 @01:22PM (#6419114)
Bleh. That definition of unit tests is so bland as to not differentiate between any kind of testing. That definition explicitly states that having a person (like QA?) go through the app and see what happens also constitutes unit testing. And that's bullshit, manual testing is not unit testing. And neither is testing an entire module at a time.

A useful discussion on the terminology problem can be found here: http://c2.com/cgi/wiki?StandardDefinitionOfUnitTest

Most definitions define unit testing as testing the "smallest piece of code that can be tested in isolation". Then my criticism definitely applies.

And given my code reviews, it's obvious that the vast majority of programmers see unit testing as testing every individual function/method in isolation. This actually hides problems by increasing total source code (actual code and the tests + "compromises" for testability) and locks down internal structure of supposedly encapsulated logic. Both are very, very bad things.

Re:Cover your PHP legacy code with 1000 unit tests in just f... by upthedale on Thursday September 19, 2013 @10:09AM (#6411697)
Check out the MSR project Pex (for .Net, not PHP however) http://research.microsoft.com/en-us/projects/pex/

It is designed to generate input for your code (the public surface by default) to determine whether it runs correctly. It can use code contract features in .Net to help inform whether your code is correct. It is great for finding those 'weird cases', and where you find a particularly interesting case, it is easy to add it as a test in your suite.

You can see it used (and play around yourself) through the browser here: http://www.pexforfun.com

Re:Cover your PHP legacy code with 1000 unit tests in just f... by strictfp on Thursday September 19, 2013 @10:25AM (#6411802)
You're probably testing too much. Take Kent Becks advice and only write a test when you can bet a dollar that it would fail. Don't write tests for things which you never fail at. BTW, the term "unit test" can mean many things depending on who you ask. I prefer to stick with the general term "test".
Re:Cover your PHP legacy code with 1000 unit tests in just f... by twistedpair on Thursday September 19, 2013 @11:23AM (#6412158)
This works until you make a significant refactoring. If you have great coverage, you are pretty sure everything's jiving correctly. Not sure what kind of refactoring tools existed back in the SmallTalk days for Beck.
Re:Cover your PHP legacy code with 1000 unit tests in just f... by strictfp on Thursday September 19, 2013 @03:15PM (#6413604)
The OP said that unit testing sucks because it can be automated. If your tests are so simple that they can be automated I would argue that they are useless, because you're not really testing functionality, but more boilerplate. You can usually skip underlying boilerplate tests if you test the functionality (within reason). Focusing on the right level and skipping the lowest level actually makes refactoring easier, since you have a degree of freedom at the very bottom left.
Re:Cover your PHP legacy code with 1000 unit tests in just f... by twistedpair on Thursday September 19, 2013 @04:58PM (#6414258)
Use a boilerplate test generator if you need boilerplate tests, such as Google's CodePro. ;)
Re:Cover your PHP legacy code with 1000 unit tests in just f... by harrytuttle on Thursday September 19, 2013 @09:18AM (#6411395)
I thought that was system integration testing?
Re:Cover your PHP legacy code with 1000 unit tests in just f... by badman_ting on Thursday September 19, 2013 @11:14AM (#6412106)
It is. Used in addition to (not instead of!) unit testing.