12/9每日例会
完成代码测试
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class) // 测试类指定特殊的运行器org.junit.runners.Parameterized
public class RoomTest {
// 测试参数
private String name;
private String address;
private String expected; // 预期结果
public RoomTest(String name, String address, String expected) {
this.name = name;
this.address = address;
this.expected = expected; }
// 存放测试用例的方法,数组中的数据对应测试参数
@Parameters
public static Collection
return Arrays.asList(new String[][] {
{ "实验室1号", "西十二N101", "succeed" },
{ "实验室2号", "西十二N102", "succeed" },
{ "实验室3号", "西十二N103", "succeed" },
{ "实验室4号", "", "failed" },
{ "", "西十二N105", "failed" }, }); }
// 参数化测试方法
@Test
public void testIsLegal() {
Room room = new Room();
room.setName(name);
room.setAddress(address);
String result = room.isLegal();
assertEquals(expected, result);
System.out.println("------------------------------------------------");
System.out.println("实验室名称:" + room.getName() + " 实验室地址:" + room.getAddress());
System.out.println("预期结果:" + expected + " 实际结果:" + result);
}
}