Question

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.

Was it helpful?

Solution 5

OTHER TIPS

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

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top