黑马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);
    }

}

有问题及时交流!

相关推荐
没有bug.的程序员2 分钟前
Java 并发容器深度剖析:ConcurrentHashMap 源码解析与性能优化
java·开发语言·性能优化·并发·源码解析·并发容器
kk哥88991 小时前
分享一些学习JavaSE的经验和技巧
java·开发语言
栈与堆1 小时前
LeetCode 21 - 合并两个有序链表
java·数据结构·python·算法·leetcode·链表·rust
lagrahhn2 小时前
Java的RoundingMode舍入模式
java·开发语言·金融
鸽鸽程序猿2 小时前
【JavaEE】【SpringCloud】注册中心_nacos
java·spring cloud·java-ee
云上凯歌2 小时前
01 GB28181协议基础理解
java·开发语言
Coder_Boy_2 小时前
基于SpringAI的在线考试系统-考试系统DDD(领域驱动设计)实现步骤详解
java·数据库·人工智能·spring boot
毕设源码-钟学长2 小时前
【开题答辩全过程】以 基于Java的运动器材销售网站为例,包含答辩的问题和答案
java·开发语言
workflower2 小时前
软件需求规约的质量属性
java·开发语言·数据库·测试用例·需求分析·结对编程
TracyCoder1233 小时前
Java String:从内存模型到不可变设计
java·算法·string