Unit Testing libraries in PHP

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply

My preferred Unit Testing library is...

PHPUnit
0
No votes
SimpleTest
7
58%
I don't use Unit Tests...
5
42%
 
Total votes: 12

User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Unit Testing libraries in PHP

Post by Maugrim_The_Reaper »

Since its about a tool and not a question on writing them I put it here...

I've spent the last few months tinkering with SimpleTest, and recently thought about looking at PHPUnit2 - what I'm not clear on is where they differ, and which one people prefer. PHPUnit2 (outwardly at least) seems to see a lot more development, and the 3.0.0 alpha looks like its adding some new features. (and well, PHPUnit looks kind of nicer what with the wealth of documentation, the flashy output, and such).

Is there a significant difference between the two? Which do you prefer using? Do both integrate well into Eclipse (IDE)?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm still not sold on Pear being used for everything, so I go with SimpleTest. Not that they are all that different, but since the author actually posts here, it gets more weight. Beyond that, it was the most straight forward. Granted, it took me awhile to actually sit down and force myself to figure it out. Marcus' tutorials and documentation helped a lot once I had the patience to read it.
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

McGruff uses SimpleTest, so I use it too. :)

I've never actually took a close look at PHPUnit2.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Same here. Didn't really know there was a PHPUnit2. I really like SimpleTest's system.
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

Simpletest is good indeed. It's available as Eclipse plugin as well.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I still need to jump on this bandwagon :)

Most likely I'll go with simpletest because it look like a few people around here can help me out with that one - but someone mentioned the examples in the docs don't even pss the tests with PHP5, is that right?

Can I unit test something once it's already been written or is that completely besides the point? Most people seem to write test, and then write code the pass the test.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Most likely I'll go with simpletest because it look like a few people around here can help me out with that one - but someone mentioned the examples in the docs don't even pss the tests with PHP5, is that right?
That was me ;). The example on the site fails because of a minor error or two - not sure whether that has been fixed yet. The remaining example is pretty good, and very concise. Might want to look for other tutorials to fill in some of the blanks you'll get left with from a quick overview. I would say it's not hard to pickup - it's like a mini-language, you need some practice but not much. Can measure the early learning curve in hours...
Can I unit test something once it's already been written or is that completely besides the point? Most people seem to write test, and then write code the pass the test.
Yes, you can. Though I would suggest writing the tests first-off without referencing the class too much (even if the class exists it might offer a few new insights). Then amend them, or the class to pass them. It's also a good idea to write tests before making any changes to an existing class - so you can change, test, change, test, in a way that let's you catch bugs fast. One thing I found hard originally is that in writing tests you may find some classes need some additional methods to even allow testing. For example, it you read my thread on ServiceLocator/Singleton/Registry (last 2 days) I needed a hasService/hasSearchLocation methods so my tests could check if such existed (basic getters for a private property). This extra bits and pieces are used solely for testing. I've seen a few people mention classes should also be written to facilitate easier testing...so that falls under this heading.

PHPUnit has received 0 votes so far...hmmm. Another factor I though of - PHPUnit requires PEAR I think, but SimpleTest can be bundled with a distributed application easily.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Maugrim_The_Reaper wrote:
Can I unit test something once it's already been written or is that completely besides the point? Most people seem to write test, and then write code the pass the test.
Yes, you can. Though I would suggest writing the tests first-off without referencing the class too much (even if the class exists it might offer a few new insights).
Well then, if I'm gonna jump on the bandwagon it might as well be for something useful and practical. I'll try to include some tests with the next release of swift :)

/goes off to get simpletest
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

d11wtq wrote: Well then, if I'm gonna jump on the bandwagon it might as well be for something useful and practical. I'll try to include some tests with the next release of swift :)

/goes off to get simpletest
You might also have to look into one of Marcus's other projects fakemail to help out in your testing.
Post Reply