ErrorCollector Rule

ErrorCollector允许发现第一个问题之后继续执行测试代码.(比如:搜索表中所有有问题的行,并报告这些行):

package com.junit.learning;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;

public class ErrorCollectorTwiceTest {
    @Rule
    public ErrorCollector collector = new ErrorCollector();

    @Test
    public void example() {
        collector.addError(new Throwable("first thing went wrong"));
        collector.addError(new Throwable("second thing went wrong"));
    }
}

运行结果如下:

java.lang.Throwable: first thing went wrong
java.lang.Throwable: second thing went wrong
Copyright © www.gitbook.com/@herryZ 2016 all right reserved,powered by Gitbook该文件修订时间: 2017-03-13 05:37:11

results matching ""

    No results matching ""