zoukankan      html  css  js  c++  java
  • IDEA 中的 Junit 单元测试

    以算数中加法乘法说明Junit怎样使用:

    package com.gxc.cal;
    
    public class Calu {
    
        public int add(int n1,int n2){
            return n1+n2;
    
        }
    
        public int plus(int n1,int n2){
            return n1*n2;
    
        }
    }
    
    

    Idea中按“ctrl + shift + t”开启单元测试:
    在单元测试中加入Assert断言方法

    package com.gxc.cal;
    
    import org.junit.After;
    import org.junit.Assert;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.*;
    
    public class CaluTest {
        Calu c = new Calu();
    
    
        @Test
        public void add() {
    
            int res = c.add(2, 3);
            Assert.assertEquals("OK", 5, res);
    
        }
    
        @Test
        public void plus() {
            Assert.assertEquals("OK", 6, c.plus(2, 3));
    
        }
    }
    
  • 相关阅读:
    stl-序列式容器
    BFS
    Hash
    二分法
    草稿1
    红黑树的左旋、右旋和颜色变换
    动态规划
    自动驾驶-安全
    二叉树

  • 原文地址:https://www.cnblogs.com/raising/p/13295613.html
Copyright © 2011-2022 走看看