• 四、Junit参数化设置


    package com.myz.util;
    
    import static org.junit.Assert.*;
    
    import java.util.Arrays;
    import java.util.Collection;
    
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.junit.runners.Parameterized;
    import org.junit.runners.Parameterized.Parameters;
    
    @RunWith(Parameterized.class)
    public class JunitParameterTest {
        
        /**
         * 1.更改默认的运行器为@RunWith(Parameterized.class)
         * 2.声明变量来存放预期值和结果值
         * 3.声明一个返回值为collection的公共静态方法,并使用@Parameters进行修饰
         * 4.为测试类声明一个带参数的公共构造函数,并在其中为之声明变量赋值
         */
        
        int expected=0;
        int input1=0;
        int input2=0;
        
        @Parameters
        public static Collection<Object[]> t(){//保存参数
            return Arrays.asList(new Object[][]{
                {3,1,2},
                {4,2,2}
            });
        }
    
        public JunitParameterTest(int expected, int input1, int input2) {
            this.expected = expected;
            this.input1 = input1;
            this.input2 = input2;
        }
        
        @Test
        public void testAdd(){//将参数传入,测试
            assertEquals(expected,new Calculate().add(input1, input2));
        }
    }
  • 相关阅读:
    目标检测:YOLOV2
    目标检测:YOLOV1
    格拉姆矩阵(Gram matrix)详细解读
    Java 线程Thread.Sleep详解
    luogu2429 制杖题
    luogu2441 角色属性树
    luogu2398 SUM GCD
    luogu2303 [SDOI2012] Longge的问题
    luogu2054 洗牌 同余方程
    线性同余方程
  • 原文地址:https://www.cnblogs.com/myz666/p/8465471.html
Copyright © 2020-2023  润新知