API(Properties、单元测试、断言)
Properties
1、父类是Hashtable,支持持久化(支持序列化)
2、映射类的键和值的类型都是String类型
3、当作配置文件来使用
4、存
1)创建对象
Properties p=new Properties();
2)往映射添加元素(键和值的类型都是String类型)
p.setProperty(“name”,“lili”);
3)存储
p.store(new FileOutputStream(“person.properties”),“this is a girl…”);
5、读
1)创建对象
Properties p=new Properties();
2)加载文件信息
p.load(new FileInputStream(“person.properties”));
3)通过键来获取值
System.out.println(p.getProperty(“name”));
4)列举数据—展示数据
p.list(System.out);
单元测试
1、步骤
1)导入测试库
2)限制测试方法(不能有返回值、不能有参数、不能是静态)
断言
对结果的预测,如果预测成功则正常执行如果预测失败则报错
使用断言需要开启断言
:后面可以设置出错原因。
eg:assert num<5:“错误原因是num值大于10”;//