美文网首页
System Rules 更好的测试

System Rules 更好的测试

作者: LinkedIn | 来源:发表于2017-07-31 14:37 被阅读0次

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"));
    }
}

相关文章

  • System Rules 更好的测试

    1:编写测试事例时候,我们要从控制台拿到数据与断言进行对比,通常要编写jdk 标准输出的屏蔽控制器.文章标题的包,...

  • PTE Core Vocabulary-22

    1. protocol A protocol is a system of rules about the cor...

  • 2019-01-25

    1.rules and system 规则和制度 IOC found systemic manipulation ...

  • 交易策略大宝库NO.002:The System:Extreme

    The System:Extreme TMA. Entry Rules: 入场规则 1- We will firs...

  • system-rules捕获被catch的异常

    断言,对于在方法层面已经被捕获的一场,没法通过单元测试再次捕获异常,可以通过sys-rules对控制台的ERROR...

  • 2020-01-17

    测试标题1 测试标题2 测试段落 --测试颜色-- //代码测试int main(){System.out.pri...

  • 新特性

    //判断是属于测试还是应用 //#define X using System; using System.Diag...

  • Python Unit Test 单元测试

    软件测试中分很多种,常见如下: 压力测试 Stress Test 系统测试 System Test 集成测试 In...

  • “遇见…”计划:020/300

    学会规则,有助于做得更好(Learn the Rules and Then Play Better) "你要学会游...

  • 测试文章

    测试文章 System.out.println("hello word");

网友评论

      本文标题:System Rules 更好的测试

      本文链接:https://www.haomeiwen.com/subject/vaqrlxtx.html