Unit testing?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Domsore
Forum Commoner
Posts: 46
Joined: Wed Jan 26, 2011 7:07 pm

Unit testing?

Post by Domsore »

I saw a lecture about extreme programming in the tutorials section and whilst I understood it, he mentioned something about Unit Testing and i've also seen the term thrown about quite a bit on the forum, could someone explain the term? Or reference to some reading material?

Thanks in advance,

Dom
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Unit testing?

Post by Jonah Bron »

http://www.google.com/search?q=unit+testing :google:

Unit testing is a very powerful tool that allows one to keep track of the "functioning" state and the expected behavior of code automatically, along with other things. The mainstream implementation is PHPUnit.

Hit it, Josh! :teach:
Last edited by Jonah Bron on Wed Feb 09, 2011 4:57 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Unit testing?

Post by John Cartwright »

I wouldn't recommend using Simpletest, since it's no longer under active development.

But seriously, it will revolutionize the way you program. By defining expected results by coding your tests first, then writing your code to pass the tests, you will find you will create much better code. It also is godsend when refactoring, because you can run all your tests to see if anything is broken, whereas otherwise bugs could easily go unnoticed.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Unit testing?

Post by Jonah Bron »

John Cartwright wrote:I wouldn't recommend using Simpletest, since it's no longer under active development.
Ah, I didn't know that.
Domsore
Forum Commoner
Posts: 46
Joined: Wed Jan 26, 2011 7:07 pm

Re: Unit testing?

Post by Domsore »

At first glance, it looks a little confusing, however, im sure i'll get my head around it.

@John I use netbeans and I remember you saying you had and issue with PHPUnit and netbeans together? Is this something I should look out for?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Unit testing?

Post by josh »

Most developers use it as a development methodology, called test driven development. Rather than worrying about how to get a job done, you first are forced to focus on defining what the job is. It's akin to writing your user guide before the program.

For example in the software produce I sell there are literally millions of possible ways it could be configured by the user. In order to make sure I don't accidentally remove or alter previously built functionality in such a complex program, I use unit tests to "pin down" the way my software currently works.

A unit test differs from testing through your browser. It's like you take a small piece of code and run it on "life support" outside of the rest of the program, its some Frankenstein stuff. If your code is unit tested it can be run outside of it's original program. This promotes re-use across projects.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Unit testing?

Post by social_experiment »

josh wrote:A unit test differs from testing through your browser. It's like you take a small piece of code and run it on "life support" outside of the rest of the program, its some Frankenstein stuff. If your code is unit tested it can be run outside of it's original program. This promotes re-use across projects.
Now i understand what unit testing is about (kindoff). I was about to ask how it differs from normal 'browser testing' but this answered it for me.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Re: Unit testing?

Post by alvinphp »

Unit testing is the only way to go
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Unit testing?

Post by onion2k »

I still use SimpleTest. It might not be under development any more but it does everything you need (for now) and it does it well.

For testing your Javascript stuff I'd recommend QUnit.
Post Reply