Alex,

I quite agree - however in this case the function I am thinking of is a
static method of a class so there's no constructors etc but it's private
to the class, and hence can't be tested externally. Likewise, I don't
think I want to make it protected, because it's not something I want
over-ridden should someone inherit the class - but that's another
matter. Point is I'm happy with it being private, or at least internal.

Basically, to quickly test this code (without trying to create several
users which would result in all sorts of db calls to validate various
pieces of data) I actually copied the entire function to a form in a
test project, and hit it with about 20 passwords to ensure each one gave
the correct result. But this means that if I change the rules (which
will happen, because the rules are very basic as of now and the owner of
the system will add more rules later) I will have to re-copy it out and
ensure that the same tests give the right result.

Another idea I had was to use conditional compilation like this:

[Conditional("DEBUG")] public static bool testValidatePassword()

And make that simply a wrapper to the private static ValidatePassword
function. This way I can use Nunit to unit test more atomic functions
rather than the global functions (some of which require certain data
states etc which makes unit testing the app _very_ difficult from the
top level).

Thoughts?

Dino


-----Original Message-----
From: dotnet discussion [mailto:[EMAIL PROTECTED]] On Behalf Of
Alex Henderson
Sent: Wednesday, 17 April 2002 17:25
To: [EMAIL PROTECTED]
Subject: Re: [DOTNET] .NET testing tools


Unit tests are generally used for testing exposed and isolated pieces of
functionality in a repeatable fashion - with that in mind if your unit
tests are well written any adverse changes to private functions will
have repercussions for the exposed public methods, which you'll pick up
the next time the test suite is executed.

What your looking for isn't provided by NUnit and in fact seems of very
limited use in general, ie. Your testing system will need to find the
class, create an instance of it with a constructor the user would choose
(or always using the default constructor if available) and then select
the function, enter parameters and execute... I already see a problem
arising that a lot of classes people write don't live inside plastic
bubbles... they require multiple method calls to put an object in a fit
state for use... and often this requires other objects and so on... it's
just not going to work very well for anything but the most basic of
situations...

Another option for this private functionality is to make it "protected"
instead of private - then inherit from the class ie.

class a
{
        protected bool methoda(int param1)
        {
        }
}

class testwrapper_a : a
{
        public bool TestMethoda(int param1)
        {
                return methoda(param1);
        }
}

However when would you ever have private methods in a class that never
get called by any properties / public methods... and if so what are they
there for?

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.349 / Virus Database: 195 - Release Date: 15/04/2002

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to