Junit多组测试数据测试

使用 Junit 指定多组测试数据进行测试。

创新互联公司长期为上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为头屯河企业提供专业的成都网站建设、网站建设,头屯河网站改版等技术服务。拥有10年丰富建站经验和众多成功案例,为您定制开发。

测试方法使用的 SHA3Utils 代码仓库地址: java-core

Parameterized 测试

批量指定多个待测参数, 按数据逐一测试


import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.List;

/**
 * Description: JunitTest 批量指定多个待测参数, 按数据逐一测试
 * <p>Blog: http://blog.wxcsdb88.com</p>
 *
 * @author wxcsdb88
 * @since 2017-12-10 00:21
 **/
@RunWith(Parameterized.class)
public class JunitTestParameterizeDemo {
    private String input;

    public JunitTestParameterizeDemo(String input) {
        this.input = input;
    }

    @Parameterized.Parameters
    public static List getParams() {
        return Arrays.asList("hello", "hi", "good morning", "how are you");
    }

    @Test
    public void sha224() throws Exception {
        String result = SHA3Utils.sha224(input);
        System.out.println(String.format("input is %s, SHA3-224 output: %s", input, result));
    }

    @Test
    public void sha256() throws Exception {
        String result = SHA3Utils.sha256(input);
        System.out.println(String.format("input is %s, SHA3-256 output: %s", input, result));
    }

    @Test
    public void sha384() throws Exception {
        String result = SHA3Utils.sha384(input);
        System.out.println(String.format("input is %s, SHA3-384 output: %s", input, result));
    }

    @Test
    public void sha512() throws Exception {
        String result = SHA3Utils.sha512(input);
        System.out.println(String.format("input is %s, SHA3-512 output: %s", input, result));
    }
}

Theories 测试

提供一组参数的排列组合值作为待测试方法的输入参数, 按照方法逐一测试


import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;

/**
 * Description: theories 提供一组参数的排列组合值作为待测试方法的输入参数, 按照方法逐一测试
 * <p>Blog: http://blog.wxcsdb88.com</p>
 *
 * @author wxcsdb88
 * @since 2017-12-10 00:21
 **/
@RunWith(Theories.class)
public class JUnitTestDemoTheories {
    @DataPoints
    public static String[] inputs = {"hello", "hi", "good morning", "how are you"};

    @Theory
    public void sha224Theories(String input) throws Exception {
        String result = SHA3Utils.sha224(input);
        System.out.println(String.format("input is %s, SHA3-224 output: %s", input, result));
    }

    @Theory
    public void sha256(String input) throws Exception {
        String result = SHA3Utils.sha256(input);
        System.out.println(String.format("input is %s, SHA3-256 output: %s", input, result));
    }

    @Theory
    public void sha384(String input) throws Exception {
        String result = SHA3Utils.sha384(input);
        System.out.println(String.format("input is %s, SHA3-384 output: %s", input, result));
    }

    @Theory
    public void sha512(String input) throws Exception {
        String result = SHA3Utils.sha512(input);
        System.out.println(String.format("input is %s, SHA3-512 output: %s", input, result));
    }
}

网站题目:Junit多组测试数据测试
标题网址:https://www.cdcxhl.com/article40/ipjiho.html

成都网站建设公司_创新互联,为您提供App设计企业建站网站收录动态网站外贸网站建设Google

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

外贸网站建设