黑马2024AI+JavaWeb开发入门Day03-Maven-单元测试飞书作业

视频地址:哔哩哔哩

讲义作业飞书地址:飞书

作业比较简单,随便写了写

java 复制代码
package org.example;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

public class EmpServiceTest {
    public EmpService empService;
    @BeforeEach
    public void testBefore(){
        empService = new EmpService();
    }

    @Test
    public void testIsBeijing(){
        boolean result = empService.isBeijing("110101199001011234");
        System.out.println(result);
        Assertions.assertEquals(true, result);
    }

    @Test
    public void testGetAge(){
        Integer result = empService.getAge("110101199001011234");
        System.out.println(result);
        Assertions.assertEquals(34, result);
    }

    @Test
    public void testGetGender(){
        String result = empService.getGender("110101199001011234");
        System.out.println(result);
        Assertions.assertEquals("男", result);
    }

    @Test
    public void testGetYear(){
        String result = empService.getYear("110101199001011234");
        System.out.println(result);
        Assertions.assertEquals("1990", result);
    }

    @Test
    public void testGetMonth(){
        String result = empService.getMonth("110101199001011234");
        System.out.println(result);
        Assertions.assertEquals("01", result);
    }

    @ParameterizedTest
    @CsvSource({
            "610110201909091231, 5",
            "110110201509091109, 9",
            "510310198812120931, 35"
    })
    public void testGetAge2(String idcard, Integer age){
        Integer result = empService.getAge(idcard);
        System.out.println(result);
        Assertions.assertEquals(age, result);
    }

}

有问题及时交流!

相关推荐
ffyyhh99551134 分钟前
idea自动生成注释
java·ide·intellij-idea
showpingzhang35 分钟前
Intellij IDEA2023 创建java web项目
java·intellij-idea
酷爱码1 小时前
python和Java的区别
java·开发语言
Cloud_.2 小时前
Spring Boot整合Redis
java·spring boot·redis·后端·缓存
盖世英雄酱581362 小时前
Java开发工程师必须掌握的线程知识指南
java
小学仔2 小时前
leetcode -编辑距离
java·算法·动态规划
快来卷java2 小时前
RabbitMQ 技术详解:异步消息通信的核心原理与实践
java·分布式·rabbitmq
float_六七2 小时前
C++中的搜索算法实现
java·c++·算法
写文章的大米2 小时前
Spring IOC 指南
java·spring
小刘|2 小时前
Mybatis_Plus中的常用注解
java·spring·mybatis