视频地址:哔哩哔哩
作业比较简单,随便写了写
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);
}
}
有问题及时交流!