Nice TWiki > Doc > DevelopmentTools > UnitTesting (r1.5) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }


The basic idea is that you write test methods inline with the code you want to test.

package hello;

// Functionality of the package
public void printHello(PrintWriter w)
  // Implementation

// Now, let's test it
void _test()
  let result = new StringWriter();

  printHello(new PrintStream(s);

  assert result.toString().equals("Hello");

void _testSomethingElse()
{ ... }

Now, compile your package: nicec -a hello.jar hello. And test it: niceunit --classpath hello.jar hello. It will run every method in the package whose name starts with _test, and report errors for any that raises an assertion error or other exceptions.

(We could very simply add the functionality in nicec to start the unit tests if the compilation succeded. Should this by default be turned on or off?)

There is also an Ant task to start niceunit, and the Maven plugin automatically starts testing as needed.

Design questions

One important design specificity is that test code is close to the code it tests, typically in the same file. You could of course put it in a different file (then you won't have access to private features) or in a different package (e.g. hello.test), where you can test only public features of =hello. These three possibilities actually allow you to do, respectively, white box testing (testing the implementation, including private memebers), black box testing of the interface visible to the package, and public black box testing.

Is this good? Is this heretic? (If it's heretic, is that bad or good? :-)


It is also possible to make use of the JUnit framework. At the moment it is not very convenient to do so, but that could be helped.

A question is: is it important to make use of JUnit? There are actually two issues:

-- DanielBonniot - 18 Feb 2004

No. It's only important that there is a way to write nUnit-style tests

Yes. Acceptance. It says Nice plays well with others. -- IsaacGouy - 19 Feb 2004

Topic UnitTesting . { Edit | Attach | Ref-By | Printable | Diffs | r1.8 | > | r1.7 | > | r1.6 | More }
Revision r1.5 - 03 Jul 2004 - 03:03 GMT - DanielBonniot
Parents: WebHome > DevelopmentTools
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.