package testing;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
public class SimpleTest extends TestCase {
public void testEmptyAgain() {
List list = new ArrayList();
assertEquals(0, list.size());
}
public void testEmpty() {
List list = new ArrayList();
assertEquals(1, list.size());
}
}
* * * * *
package testing;
import java.io.*;
import java.util.Date;
import junit.framework.*;
import junit.framework.Test;
import org.junit.runner.Result;
import junit.framework.TestResult;
import org.junit.runner.JUnitCore;
import org.apache.tools.ant.BuildException;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
import org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter;
public class SimpleSuite {
public static void main(String[] args) {
TestResult r = new TestResult();
TestSuite ts = new TestSuite("SimplengTestSuite");
JUnitTest jut = new JUnitTest("SimplengJUnitTest");
XMLJUnitResultFormatter xjrf = new XMLJUnitResultFormatter();
try {
xjrf.startTestSuite(jut);
OutputStream w = new FileOutputStream(new File("report.xml"));
xjrf.setOutput(w);
r.addListener(xjrf);
TestCase tc1 = (TestCase) Class.forName("testing.SimpleTest").newInstance();
tc1.setName("testEmpty");
ts.addTest(tc1);
long start = new Date().getTime();
ts.run(r);
long end = new Date().getTime();
jut.setCounts(r.runCount(), r.failureCount(), r.errorCount());
jut.setRunTime(end - start);
xjrf.endTestSuite(jut);
w.close();
} catch (Exception e){
e.printStackTrace();
}
}
}
Wednesday, November 09, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment