본문 바로가기

Java27

Spring boot @MockBean Example @SpringBootTest class StudentRepositoryTest { @Autowired Student student; @Autowired StudentGrades studentGrades; @MockBean private StudentRepository studentRepository; @Autowired private StudentService studentService; @BeforeEach void beforeEach() { student.setFirstName("Eric"); student.setLastName("King"); student.setEmailAddress("eric.roby@asdf.com"); student.setStudentGrades(studentGrades); .. 2022. 5. 22.
Spring boot Mockito Example - @Mock & @InjectMocks @SpringBootTest class StudentRepositoryTest { @Autowired Student student; @Autowired StudentGrades studentGrades; @Mock private StudentRepository studentRepository; @InjectMocks // inject mock dependencies private StudentService studentService; @BeforeEach void beforeEach() { student.setFirstName("Eric"); student.setLastName("King"); student.setEmailAddress("eric.roby@asdf.com"); student.setStud.. 2022. 5. 22.
Spring boot Test with Mockito Mocking Framworks mockito easymock jmockit Mockito in spring boot mockito framwork is builtin spring boot dependency -> spring-boot-starter-test Mockito Test Process setup set expectations with mock reponses execute call the method want to test assert check the result and verify that it is expected result verify optionally.. verify calls (how many times called etc..) Mokcito Test in Spring boot .. 2022. 5. 22.
Unit Test - ParameterizedTest Source annotation @ValueSource -> Array of values: Strings, ints, doubles, floats etc @CsvSource -> Array of CSV String values @CsvFileSource -> CSV values read from a file @EnumSource -> Enum constant values @MethodSoruce -> Custom method for providing values //sample @DispleName("Testing with Small data file") @PrameterizedTest(name="value={0}, expected={1}") //0번째 인덱스의 값이 1 @CsvFileSource(res.. 2022. 5. 21.
Java Conditional Unit Test @Test @Disabled("Don't run until JIRA #123 is resolved") void testDisabled(){ // } @Test @EnabledOnOs(OS.WINDOWS) void testForWindowsOnly(){ } @Test @EnabledOnOs(OS.MAC) void testForMacOnly(){ } @Test @EnabledOnOs({OS.MAC,OS.WINDOWS}) void testForMacAndWindowsOnly(){ } @Test @EnabledOnOs(OS.LINUX) void testForLinuxOnly(){ } @Test @EnabledOnJre(JRE.JAVA_17) void testForJava17(){ } @Test @EnabledO.. 2022. 5. 21.
spring aop AOP DI 추가 implementation 'org.springframework.boot:spring-boot-starter-aop' controller @Slf4j @RestController @RequestMapping("/api") public class RestApiController { @GetMapping("/get/{id}") public String get(@PathVariable Long id, @RequestParam String name){ return String.format("%s-%s",id, name); } @PostMapping("/post") public UserDto post(@RequestBody UserDto userDto){ return userDto; } @Dec.. 2021. 11. 7.