views:

249

answers:

5

Some of us still "live" in a programming environment where unit testing has not yet been embraced. To get started, the obvious first step would be to try to implement a decent framework for unit testing, and I guess xUnit is the "standard".

So what is a good starting point for implementing xUnit in a new programming language?

BTW, since people are asking: My target environment is Visual Dataflex.

+1  A: 

I'd suggest that a good starting point would be to use xunit on a couple of other languages to get a feel for how this style of unit test framework works. Then you'll need to go in depth into the behaviour and start working out how to recreate that behaviour in a way that fits with your new language.

David Arno
+2  A: 

Which language is it for - there are quite a few in place already.

Chris Kimpton
For me specifically, I am looking into implementing unit testing on Visual Dataflex. My question is intended to be lanugage-agnostic, though.
Ola Eldøy
+2  A: 

If this is stopping you from getting started with writing unit tests you could start out without a testing framework.

Example in C-style language:

void Main() 
{
  var algorithmToTest = MyUniversalQuestionSolver();
  var question = Answer to { Life, Universe && Everything };

  var actual = algorithmToTest(question);
  var expected = 42;
  if (actual != expected) Error();

  // ... add a bunch of tests
}

Example in Cobol-style language:

MAIN.
  COMPUTE EXPECTED_ANSWER = 42
  SOLVE ANSWER_TO_EVERYTHING GIVING ACTUAL_ANSWER
  SUBTRACT ACTUAL_ANSWER FROM EXPECTED_ANSWER GIVING DIFFERENCE
  IF DIFFERENCE NOT.EQ 0 THEN
    DISPLAY "ERROR!"
  END-IF

  * ... add a bunch of tests
  STOP RUN

Run Main after you are finished with a changed (and possibly compile) on your code. Run main on the server whenever someone submits code to your repository.

When you get hooked, Look more for a framework or see if you possibly could factor out some of the bits from Main to your own framework.

Hallgrim
+1  A: 

I created a decent unit test framework in VFP by basing it on the code in Test Driven Development: A Practical Guide, by David Astels. You'll get a long way by reading through the examples, understanding the techniques and translating the Java code into your language.

Tom
+1  A: 

I found Pragmatic Unit Testing in C# with NUnit very helpful!

Ola Eldøy