Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. 강한 결합:

    • Notification Feature가 User Feature에 강하게 결합되어, User Feature 변경 시 Notification Feature도 영향을 받습니다.

  2. MSA 독립성 원칙 위반:

    • 각 Feature는 독립적으로 배포 및 유지보수가 가능해야 하지만, 위와 같은 구조에서는 두 Feature가 독립적으로 동작하기 어렵습니다.

  3. 테스트 어려움:

    • Notification Feature를 테스트하려면 User Feature의 전체 구현이 필요할 수 있습니다.

Expand
title모의 객체를 사용한 독립적 테스트

모의 객체를 사용한 독립적 테스트

테스트 시 실제 User Feature를 사용하지 않고 Mock 객체를 활용하여 독립적인 테스트를 수행할 수 있습니다.

구현 예시:

  • UserClientPort 인터페이스 정의:

Code Block
public interface UserClientPort {
    UserResponse getUser(String userId);
}
  • NotificationService 테스트:

Code Block
@ExtendWith(MockitoExtension.class)
public class NotificationServiceTest {

    @Mock
    private UserClientPort userClientPort;

    @InjectMocks
    private NotificationService notificationService;

    @Test
    public void testNotifyUser() {
        // Mock 동작 정의
        String userId = "123";
        UserResponse mockResponse = new UserResponse(userId, "John Doe", "john.doe@example.com");
        Mockito.when(userClientPort.getUser(userId)).thenReturn(mockResponse);

        // 테스트 실행
        boolean result = notificationService.notifyUser(userId);

        // 검증
        assertTrue(result);
        Mockito.verify(userClientPort).getUser(userId);
    }
}

장점:

  • User Feature와 독립적으로 Notification Feature를 테스트할 수 있습니다.

  • Mock 객체를 사용해 다양한 시나리오를 손쉽게 검증 가능합니다.

...

해결 방안

1. REST API를 사용한 간접 호출

...