zoukankan      html  css  js  c++  java
  • 软件工程第二次作业 junit测试

    软件工程第二次作业---junit测试

    1.安装eclipse工具

    • 下载 Java JDK
      enter image description here
    • 安装 JDK
      enter image description here
    • 下载 eclipse
      enter image description here
    • 安装 eclipse
      enter image description here

    2.测试工具junit

    • 测试加减乘除
      
    public class Calculate {
    
        public int add(int a, int b) {
            return a + b;
        }
    
        public int substract(int a, int b) {
            return a - b;
        }
    
        public int multiply(int a, int b) {
            return a * b;
        }
    
        public int divide(int a, int b) {
            // 这里只是最简单的测试demo,暂不做容错处理
            return a / b;
        }
    }
    
    • 建立junit test

    enter image description here

    • 导入junit测试

    enter image description here

    • 对calculate类中的加、减、乘、除四个方法进行测试的测试代码
    import static org.junit.Assert.*;
    
    import org.junit.Test;
    
    public class CalculateTest {
    
    	@Test
    	public void add(){
    	    assertEquals(100, new Calculate().add(95, 5));
    	}
    
    	@Test
    	public void substract(){
    	    assertEquals(0, new Calculate().substract(100, 100));
    	}
    
    	@Test
    	public void multiply(){
    	    assertEquals(1, new Calculate().multiply(1, 1));
    	}
    
    	@Test
    	public void divide(){
    	    assertEquals(0, new Calculate().divide(100, 101));
    	}
    
    }
    
    
    • 测试结果

    enter image description here

    结果正确

    经过学习junit测试令我掌握很多学习经验。

  • 相关阅读:
    mysql InnoDB 索引小记
    Linux shell 脚本小记
    Java中Integer的源码学习
    nginx小记
    位运算小结
    Redis小结
    CSS中nth-child和nth-of-type的简单使用
    Linux awk小记
    mysql小记--基础知识
    让44.1版本的sketch打开更高版本的sketch文件
  • 原文地址:https://www.cnblogs.com/ZhangZiYangDeBoKe/p/8623074.html
Copyright © 2011-2022 走看看