System Rules 更好的测试
测试 system 更好 rules
2023-09-11 14:17:19 时间
1:编写测试事例时候,我们要从控制台拿到数据与断言进行对比,通常要编写jdk 标准输出的屏蔽控制器.文章标题的包,能够更好的为我们进行工作.
package demo2;
import static org.junit.Assert.assertEquals;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.StandardOutputStreamLog;
import org.junit.contrib.java.lang.system.SystemErrRule;
import org.junit.contrib.java.lang.system.SystemOutRule;
public class demo1 {
@Rule // 过去写法
private final StandardOutputStreamLog log=new StandardOutputStreamLog();
//正确输出
@Rule
private final SystemOutRule sRule=new SystemOutRule();
//错误输出
@Rule
private final SystemErrRule errrule=new SystemErrRule();
@Test
public void miantest() {
sysou();
assertEquals(2, sRule.getLog());
}
private void sysou() {
System.out.println(2);
}
}
其实使用事例介绍
Clear Properties
public class MyTest {
@Rule
public final ClearSystemProperties myPropertyIsCleared
= new ClearSystemProperties("MyProperty");
@Test
public void overrideProperty() {
assertNull(System.getProperty("MyProperty"));
}
}
Provide Properties
public class MyTest {
@Rule
public final ProvideSystemProperty myPropertyHasMyValue
= new ProvideSystemProperty("MyProperty", "MyValue");
@Rule
public final ProvideSystemProperty otherPropertyIsMissing
= new ProvideSystemProperty("OtherProperty", null);
@Test
public void overrideProperty() {
assertEquals("MyValue", System.getProperty("MyProperty"));
assertNull(System.getProperty("OtherProperty"));
}
}
相关文章
- Jmeter 实现 mqtt 协议压力测试
- Python产生随机数组,测试用
- 高并发分布式系统中生成全局唯一(订单号)Id js返回上一页并刷新、返回上一页、自动刷新页面 父页面操作嵌套iframe子页面的HTML标签元素 .net判断System.Data.DataRow中是否包含某列 .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数
- Python Kafka客户端性能测试比较
- python自动化测试——自动化基本技术原理
- Appium - 自动化测试框架 - 工作原理、环境搭建
- Python接口测试实战之搭建自动化测试框架
- 测试初级必看的环境搭建的上手指南
- 《移动App测试的22条军规》——第1章,第1.1节移动App的特性
- 《树莓派渗透测试实战》——总结
- Fiddler实战之将抓到接口导入Jmeter接口测试
- 用python做测试实现高性能测试工具(2)—优化代码
- 测试关键域