What to TDD and what not?

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

What to TDD and what not?

Post by matthijs »

In another thread I read this:
Jcart wrote:Since controllers, models and views generally should not be Unit Tested since they are application specific, this is a tough one to follow.
Not? That's the first time I hear this. So if I'd build something with, say, the zend framework I don't have to worry about testing my app code?

Is this true? I just started with TDD and what I've done so far is write tests for my models and do a bit of web testing and testing of forms.
(didn't want to hijack the other thread so started a new one)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: What to TDD and what not?

Post by alex.barylski »

matthijs wrote:In another thread I read this:
Jcart wrote:Since controllers, models and views generally should not be Unit Tested since they are application specific, this is a tough one to follow.
Not? That's the first time I hear this. So if I'd build something with, say, the zend framework I don't have to worry about testing my app code?

Is this true? I just started with TDD and what I've done so far is write tests for my models and do a bit of web testing and testing of forms.
(didn't want to hijack the other thread so started a new one)
Not so much a matter of truth, but rather that of personal opinion.

Personally, I test *everything* manually anyways so once I do start unit testing I will likely test controllers/model at the least. My Views are difficult to test automatically.

In my experience they all change to frequently to ignore unit testing if your going to bother with it at all.

Cheers :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: What to TDD and what not?

Post by John Cartwright »

matthijs wrote:In another thread I read this:
Jcart wrote:Since controllers, models and views generally should not be Unit Tested since they are application specific, this is a tough one to follow.
Not? That's the first time I hear this. So if I'd build something with, say, the zend framework I don't have to worry about testing my app code?

Is this true? I just started with TDD and what I've done so far is write tests for my models and do a bit of web testing and testing of forms.
(didn't want to hijack the other thread so started a new one)
Notice how I said should not be Unit Tested. I still believe applications should be tested :D If you continue to read down the thread you linked, you'll see not everybody agrees with me :D
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

I still believe applications should be tested Very Happy
you're sure? :D

So even though not everyone agrees (never will), I still am interested to know: what is the reason you don't want to test your application specific code? because almost everything is done in your framework code and nothing can go wrong in your application classes? is it too cumbersome? If you would write, say a widgetsModel class, shouldn't that be done the TDD way?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

There's a difference between unit testing and TDD. TDD requires you write a test specifying a wanted behaviour, write the code to pass the test (achieve the behaviour), refactor as needed, and repeat. Whether it's library, framework, model, view or controller code is irrelevant - you can apply TDD to them all. I think the biggest problem in reality is that few frameworks (if any) are easy to get TDD applied with. A neat approach is to extend your unit testing framework to takeover the basic steps of getting any controller/model ready for execution (e.g. I use a post() method as a shortcut to routing/dispatching/executing Zend Framework controllers).

As for whether application code is too dynamic to be tested - there's a huge difference between TDD (design the controller; tests are coincidental) and unit testing (test, test, test). Is application code too dynamic? It can be, but I think much of that tends to be present in heavy controllers where the logic has not been refactored into more stable library classes. In essence - it's a code smell.

To further press an argument - have you looked at how prevelant controller/model/view testing is for something like Ruby Rails? Python Django? Or perhaps more interesting - how each has committed test-execution frameworks to make simulating controller runs as simple as post(), is_redirect(), etc? I think it's more a symptom of PHP's current low adoption of TDD that the main PHP frameworks seriously lack any such toolkit - not that TDD or unit testing has no place in MVC.

None of this, of course, is an excuse for not having acceptance tests ;). But not applying TDD to a controller, in my opinion, is just a throwback to pre-TDD practices and encouraged by frameworks like Zend which has, from experience, extremely little code developed using XP/Agile practices.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

I wirte tests for everything. Tests are not just for frameworks, they are for any scenario, application specific or not.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Yeah, I test just about everything, but I compartmentalize everything so when the application goes away, so does its tests.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

feyd wrote:Yeah, I test just about everything, but I compartmentalize everything so when the application goes away, so does its tests.
Ditto :)
Post Reply