zoukankan      html  css  js  c++  java
  • 单元测试

    • 单元测试: 测试对象是一个类中的方法.
    • 需要使用 JUnit 工具, 导入 junit-4.10.jarhamcrest-core-1.3.jar
    • 单元测试方法的时候, 方法命名规则: public void test方法名(){}

    测试步骤

    1. 创建名为 "test" 的 "SourceFolder文件夹", 与 "src" 同一级目录
    2. 创建与要测试的方法相同的包名
    3. 书写测试方法, 测试方法无返回值, 无参数;
        @Test
        public void testAdd(){
    
            // 获取测试方法的实例
            TestJuint test01 = new TestJunit();
    
            // 调用测试的方法, 并传入参数
            test01.testAdd(2, 3);
        }
    
        // 备注:
        //    1. @Test 是注解, 表示该方法需要进行单元测试. 需要导入 org.junit.Test 包
        //    2. testAdd() 方法上, 右键, run as ,  junit test
    
        @Ignore : 表示该方法不进行单元测试, 需要导入 org.junit.Ignore
        @Before : 表示测试任何方法之前, 会先运行 Before 注解的方法, 然后运行被测试的方法
        @After  : 表示测试任何方法之后, 会运行 After 注解的方法
    
        // 断言
        @Test
        public void testDemo(){
    
            int a = 3;
            int b = 5;
            int sum = a+b;
    
            // Assert.assertEquals("测试期望的值", "方法运行的实际值");
            Assert.assertEquals(8,sum);
        }
    

    **参考资料:** - [JavaWeb 视频教程](https://www.bilibili.com/video/av12751541/#page=4)
  • 相关阅读:
    utuntu sever1804显示中文putty可以输入中文
    windows上用putty从linux上下载文件
    2020Ubuntu server1804最新安装后的配置
    2020年ubuntu sever1804 安装和配置
    堡垒机
    防病毒网关
    审计系统
    常用网站
    AWVS的使用1
    windows Server 监控远程桌面连接信息
  • 原文地址:https://www.cnblogs.com/linkworld/p/7568387.html
Copyright © 2011-2022 走看看