본문 바로가기

jUnit

Spring boot Throwing Exception test @SpringBootTest class StudentRepositoryTest { @Autowired Student student; @Autowired StudentGrades studentGrades; @MockBean private StudentRepository studentRepository; @Autowired private StudentService studentService; @Autowired private ApplicationContext context; @DisplayName("Throw runtime error") @Test void throwRuntimeError() { Student nullStudent = (Student)context.getBean("Student"); doTh.. 더보기
Spring boot @MockBean @MockBean - includes Mockito @Mock functionality - also adds mock bean to if existing bean is there, the mock bean will replace it - thus making the mock bean available for injection with @Autowired Using @Mock @SpringBootTest class StudentRepositoryTest { @Mock private StudentRepository studentRepository; @InjectMocks private StudentService studentService; } Using @MockBean @SpringBootTest clas.. 더보기
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 .. 더보기
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.. 더보기
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.. 더보기