views:

132

answers:

3

Duplicate: http://stackoverflow.com/questions/135651/learning-unit-testing


I'm trying to develop some software for my research group to analyze and plot experimental data. I would like to make it were it's pretty error free. Would this be a situation for unit testing? If so could you possibly point me to some good references for unit testing?

+5  A: 

Pretty much any code is a good candidate for unit testing; it will help you document the intent of your code, and prove that your code works as intended. It will definitely help you find bugs before releasing your code to the rest of your group. You don't say what platform you're using, so I can't recommend a testing framework, but I can recommend Kent Beck's excellent Test Driven Development: By Example as a good general starting place.

MattK
MattK, its going to be for windows. Doing it in Python. Thanks for your help :)
Casey
+1  A: 

From my experience, unit tests are a great idea for any functionality that is not UI-related (like "is the number displayed in red if it's a negative value") in helping you to find bugs as early as possible. Thus I'd recommend writing unit tests whenever possible (and have them run automatically, e.g. nightly or even after each build, to see if some new piece of code broke anything).

ISW
even as required step before 'SVN-checkins'
RSabet
A: 

So your application needs to analyze data? Well that sounds like a test can be writen.

e.g. if you data always scores 5.25 on a Wednesday.

You could write a test.

void CheckScoreOnWeds()
{
     Assert.AreEqual( 5.25, DataAnalyzer.CalcScore(Day.Wednesday));     
}

and then write your class

class DataAnalyzer
{
    public double CalcScore( DayOfWeek Day)
    {
          //complex stuff
          return 5.25
    } 
}

There you have a unit test.

John Nolan