"Aaron M. Renn" <[EMAIL PROTECTED]> writes:
> I would like to be able to have a given java class execute more than
> one test.
OK. How's this? (ie. ignore my previous post)
The testing framework deals with classes that implement either
gnu.test.Test or gnu.test.TestPackage.
gnu.test.TestPackage is defined as:
public interface TestPackage
{
/**
* Return a set of instantiated tests.
*/
public Test[] getTests();
}
So your URLTest.java looks like:
import gnu.test.*;
import java.net.*;
import java.io.*;
public class URLTests implements TestPackage
{
public Test[] getTests() {
return (new Test[] { new SimpleURLTest(),
new URLParsingTest(),
new GetContentTest() });
}
public static class SimpleURLTest implements Test {
public String getName() {
return "Simple URL Test";
}
public Result test() {
try {
URL url = new URL("http", "www.fsf.org", 80, "/");
if (!url.getProtocol().equals("http") ||
!url.getHost().equals("www.fsf.org") ||
url.getPort() != 80 ||
!url.getFile().equals("/"))
return new Fail();
URLConnection uc = url.openConnection();
if (!(uc instanceof HttpURLConnection))
return new Fail("wrong connection type");
HttpURLConnection hc = (HttpURLConnection)uc;
hc.connect();
// try to throw an exception
BufferedReader br = new BufferedReader(new
InputStreamReader(hc.getInputStream()));
for (String str = br.readLine(); str != null; str = br.readLine())
{ }
hc.disconnect();
return new Pass();
}
catch (IOException e)
{
return new Fail(e.toString());
}
}
}
public static class URLParsingTest implements Test {
public String getName() {
return "URL Parsing Test";
}
public Result test() {
//...
return new Pass();
}
}
public static class GetContentTest implements Test {
public String getName() {
return "getContent Test";
}
public Result test() {
//...
return new Pass();
}
}
}
All your tests are in one class file, nicely organized. And there
need only be one entry in the "tests.to.run" file for URLTests.
Good solution?-)
--
Paul Fisher * [EMAIL PROTECTED]