If the test code causes a runtimeException, resulting in a build failure

20 Views Asked by At
@Test
public void signup_아이디_중복_테스트(){

    //given
    Authority authority = Authority.builder().authorityName("ROLE_USER").build();

    UserDto userDto_one = new UserDto("user_one","user1234","user_nick","[email protected]",null,null,null);
    UserDto userDto_two = new UserDto("user_one","user1234","user2_nick","[email protected]",null,null,null);

    // when
    userService.signup(userDto_one);
    RuntimeException e = assertThrows(RuntimeException.class, () ->
        userService.signup(userDto_two));

    // then
    assertThat(e.getMessage()).isEqualTo("이미 가입되어 있는 유저입니다. 아이디 중복");
}

Here's the test code, which when you run and test through the mainApp, it uses the same username to trigger a runtimeException and becomes a normal PASS through asertThat.isEqual.

java.lang.RuntimeException: 이미 가입되어 있는 유저입니다. 아이디 중복
at com.rktpdyfk.TradingMatchingService.service.UserService.signup(UserService.java:53)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:352)

However, if you try to build, the test code itself says a runtime exception appears, and you get a build fail. This should be the nature of the build that the error should not appear, right? However, the test code is intentionally triggered, so how can I get it to build normally?

I looked it up and found a build gradle setting that doesn't include the test code itself in the build. Can I just use this CODE?

//빌드가 급하게 필요할때 테스트 failed를 무시함
//test.onlyIf {
//  !project.hasProperty('test')
//}
0

There are 0 best solutions below