Re: Unit testing - suitable for all development?

From: Kylotan (kylotan_at_hotmail.com)
Date: 03/08/04


Date: 7 Mar 2004 15:15:07 -0800


"John Roth" <newsgroups@jhrothjr.com> wrote in message news:<104mo6mjpc1lq74@news.supernews.com>...

> Coupling is the enemy.
>
> The XP people have a lot of experiance with reducing
> coupling. Writing tests first, and insisting that literally
> hundreds of unit tests run in a few seconds teaches you
> how to write code with a minimum of coupling. Some of
> those lessons aren't particularly easy.

Yeah, that's what I'm guessing. I'm at the stage where I have to
wonder whether forcing myself to make the paradigm shift will be worth
the effort or not.

> The first is to see if you can redesign using a layered
> architecture. That may force you to reduce the number
> of objects that any given object depends on.

What do you mean by layered in this context? Are you talking things
like the Bridge design pattern?

> The second is to investigate mock objects, or other
> methods of stubbing out dependencies. While you do
> need to run the entire system as a unit, there is no
> reason you need to run the real production objects
> for all tests.

That seems like a nice idea, but I've been developing this system as
an evolving prototype. I add new objects and classes as I discover I
need them. Therefore there's almost no functionality there at all that
isn't needed for the system as it stands.

Here's an example of my current system: the Creature class requires a
Race class and a World class to be instantiated, as the Creature's
__init__ function relies on calling methods of these objects (not just
on their presence). Sure, technically I could create dummy objects to
pass in that have do-nothing functions, but then I break most of
Creature's accessors, which are implemented in terms of delegating to
the other objects. In turn this would make the tests meaningless.

I guess what I'm trying to say is that I create systems that arise
from the grouping of classes, and that taking the class out of context
makes it useless. I don't have many things that are low-level enough
to make sense when tested in isolation. (This contrasts heavily to my
development in C++, for example.) And the classes have very little
internal behaviour; it's all done in terms of other classes.

None of this makes testing any harder or less useful in catching bugs;
it just means that it ends up being an almost straight duplication of
my normal code, with the input handling stripped out! It hardly seems
worth the effort.

-- 
Ben Sizer


Relevant Pages

  • Re: Unit Testing an ASP.NET Website using VS2008 Pro
    ... Move your classes from App_Code to their own libraries. ... you will have no problem using a unit test framework to test your functionality. ... Publish and set nUnit to point to those files ... unexpected error in displaying the Create Unit Tests Dialog. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Unit Testing an ASP.NET Website using VS2008 Pro
    ... Publish and set nUnit to point to those files ... functionality, rather I have several classes that are in my App_Code ... to reference so that I can test my App_Code. ... unexpected error in displaying the Create Unit Tests Dialog. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Unit testing for roguelikes?
    ... functionality. ... Unit tests are most useful if you change your code. ... NetHack-De: NetHack auf Deutsch - http://nethack-de.sourceforge.net/ ... NetHack for AROS: http://bhaak.dyndns.org/nethack/nethack-for-aros.html ...
    (rec.games.roguelike.development)
  • Re: How many lines of code per programmer-hour?
    ... > with that, the bazillion of permutations... ... you only test the new objects' functionality in their ... unit tests (you assume the used objects work, ... I often refactor to nested procedures first, ...
    (borland.public.delphi.non-technical)
  • Re: CString to const char conversion
    ... > I have been using it many years with now real problems. ... When asked why I declare something sucks, I often point to issues writing ... unit tests for it. ... Such issues are typically symbolic of more important coupling issues. ...
    (comp.lang.cpp)