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.
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? :-)
| Topic UnitTesting . { Edit | Attach | Ref-By | Printable | Diffs | r1.8 | > | r1.7 | > | r1.6 | More } |
|
Revision r1.8 - 19 Apr 2005 - 10:31 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. |