spring22 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. Spring mvc async rest api /* 결제 내역 조회시 해당 결제 내역에 사용자 정보를 포함해야 한다. 사용자 정보 조회를 위해 결제아이디로 사용자 정보를 조회 후 결제 정보에 조인 시켜야 한다. 해당 프로세스를 비동기적으로 처리 하도록 한다. */ Enable Async and config thread pool @EnableAsync @Configuration public class BeanConfig { /** * @see https://kapentaz.github.io/spring/Spring-ThreadPoolTaskExecutor-%EC%84%A4%EC%A0%95/# */ @Bean("accounting-async-thread") public Executor asyncThread(){ ThreadPoolTaskExecutor .. 2021. 11. 7. 이전 1 2 3 4 다음