SuperTestCase
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import junit.framework.TestCase;
import junit.framework.TestResult;
/**
* 環境変数 fileout=true とするとファイルログを残す
*
*/
public class SuperTestCase extends TestCase {
int count = 0;
String ext = ".log";
boolean fileout = false;
static String logFilePath = "C:/temp/test" + (new SimpleDateFormat("yyyyMMdd-HHmmss")).format(new Date()) +"/";
String outFileName = null;
protected String description = null;
public SuperTestCase() {
super();
switchOut1();
String fileout = System.getProperty("fileout");
if (fileout != null && "true".equals(fileout)) {
this.fileout = true;
}
}
@Override
public TestResult run() {
return super.run();
}
@Override
protected void setUp() throws Exception {
super.setUp();
switchOut1();
System.out.println("<test className='" + getClass().getName()
+ "' testcase='" + getName() + "' >");
System.out.println("date=" + new Date());
}
private void switchOut1() {
if (fileout) {
File outDir = new File(logFilePath);
if(outDir.exists()==false){
outDir.mkdirs();
}
try {
System.out.flush();
String className = getClass().getName();
outFileName = logFilePath + className + ext;
System
.setOut(new PrintStream(new FileOutputStream(
outFileName,true)));
} catch (Exception ex) {
}
}
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
System.out.println("</test>");
}
}