junit执行之后会有一个结果展示,下面来看一下怎么获取这些结果并将其存储为一个对象
junit代码如下:
package test;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class JunitDemo {
@Before
public void bofore() {
System.out.println("bofore");
}
@After
public void after() {
System.out.println("after");
}
@Test
public void test1() {
System.out.println("test1");
Assert.assertEquals(1, 2);
}
@Test
public void test2() {
System.out.println("test2");
Assert.assertEquals(1, 1);
}
@Test
public void test3() {
System.out.println("test3");
Integer.valueOf("aede21");
}
}
首先先写两个类,分别是结果对象和结果中的方法执行结果对象
结果记录类:
package test;
import java.util.List;
public class MyResultRecorder {
String script_name;
List<MethodInfo> list;
Boolean result;
public String getScript_name() {
return script_name;
}
public void setScript_name(String script_name) {
this.script_name = script_name;
}
public List<MethodInfo> getList() {
return list;
}
public void setList(List<MethodInfo> list) {
this.list = list;
}
public Boolean getResult() {
return result;
}
public void setResult(Boolean result) {
this.result = result;
}
@Override
public String toString() {
return "MyResultRecorder [script_name=" + script_name + ", list=" + list + ", result=" + result + "]";
}
}
记录中的方法:
package test;
public class MethodInfo {
String method_name;
Boolean result;
String error_msg;
public String getMethod_name() {
return method_name;
}
public void setMethod_name(String method_name) {
this.method_name = method_name;
}
public Boolean getResult() {
return result;
}
public void setResult(Boolean result) {
this.result = result;
}
public String getError_msg() {
return error_msg;
}
public void setError_msg(String error_msg) {
this.error_msg = error_msg;
}
@Override
public String toString() {
return "MethodInfo [method_name=" + method_name + ", result=" + result + ", error_msg=" + error_msg + "]";
}
}