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

}

有问题及时交流!

相关推荐
是一个Bug10 小时前
Java主流框架面试题(一)
java·开发语言
情爱少有真诚10 小时前
Java集合框架:数据存储与操作的利器
java·开发语言·经验分享·课程设计·ai编程
工业甲酰苯胺10 小时前
【面试题】数据库事务隔离与传播属性是什么?
java·数据库·oracle
我居然是兔子10 小时前
基于字符串的专项实验:解锁Java String类的隐藏细节
java·开发语言
jiayong2310 小时前
Java 反射完全指南 - 原理与实战
java·开发语言
Mongnewer10 小时前
JAVA从0到1走过的小路
java·java从0到1
西西学代码11 小时前
Flutter---类
java·开发语言
码农小卡拉11 小时前
Java多线程:CompletableFuture使用详解(超详细)
java·开发语言·spring boot·python·spring·spring cloud
I'm Jie11 小时前
Gradle 多模块依赖集中管理方案,Version Catalogs 详解(Kotlin DSL)
android·java·spring boot·kotlin·gradle·maven
Java小白笔记11 小时前
BigDecimal用法示例
java·开发语言·spring boot