其他分享
首页 > 其他分享> > 自定义寻找bug简单框架 (还没完成)

自定义寻找bug简单框架 (还没完成)

作者:互联网

package test;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.Clock;


public class test {

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int numm=0;
BufferedWriter bw=new BufferedWriter(new FileWriter("bug1.txt"));
Deom1 d=new Deom1();
//获取deom1的字节码文件
Class cls=d.getClass();
//获取方法
Method[]methods= cls.getMethods();
for( Method method:methods) {
//判断方法是否有错
if(method.isAnnotationPresent( (Class<? extends Annotation>) test.class)) {

try {
method.invoke(d);
} catch (Exception e) {
numm++;
bw.write(method.getName()+"方法出异常了");
bw.newLine();
bw.write("异常名称"+e.getCause().getClass().getSimpleName());
bw.newLine();
bw.write("异常原因"+e.getCause().getMessage());
bw.newLine();
bw.write("==========");
bw.newLine();
bw.flush();


// TODO Auto-generated catch block

}

}
}
bw.write("本次测试一共发生了"+numm+"次bug");
bw.flush();
bw.close();
}

}

标签:java,自定义,框架,newLine,method,write,bw,import,bug
来源: https://www.cnblogs.com/koushijun575/p/15516041.html