Skip to content

Commit

Permalink
Merge pull request Team-TenTen#200 from Team-TenTen/fix/test
Browse files Browse the repository at this point in the history
[Fix]: Integration 서비스 테스트 시 `@MockBean`으로 인한 테스트 속도 저하 문제 해결.
  • Loading branch information
young970 committed Dec 13, 2023
2 parents f6ec19d + 0fa6c3a commit 176645a
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 68 deletions.
15 changes: 15 additions & 0 deletions src/test/java/com/tenten/linkhub/IntegrationApplicationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tenten.linkhub;

import com.tenten.linkhub.global.aws.s3.ImageFileUploader;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;

@ActiveProfiles("test")
@SpringBootTest
public abstract class IntegrationApplicationTest {

@MockBean
protected ImageFileUploader mockImageFileUploader;

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.member.service;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.auth.JwtProvider;
import com.tenten.linkhub.domain.auth.MemberDetails;
import com.tenten.linkhub.domain.member.model.Member;
Expand All @@ -21,7 +22,6 @@
import com.tenten.linkhub.domain.member.service.dto.MemberUpdateResponse;
import com.tenten.linkhub.domain.space.model.category.Category;
import com.tenten.linkhub.global.aws.dto.ImageInfo;
import com.tenten.linkhub.global.aws.s3.ImageFileUploader;
import com.tenten.linkhub.global.exception.DataDuplicateException;
import com.tenten.linkhub.global.exception.DataNotFoundException;
import org.assertj.core.api.Assertions;
Expand All @@ -31,12 +31,9 @@
import org.junit.jupiter.api.Test;
import org.mockito.BDDMockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.PageRequest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.core.Authentication;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;
Expand All @@ -45,20 +42,15 @@
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;

@SpringBootTest
@Transactional
@ActiveProfiles("test")
class MemberServiceTest {
class MemberServiceTest extends IntegrationApplicationTest {

@Autowired
private MemberService memberService;

@Autowired
private MemberEmailRedisRepository redisRepository;

@MockBean
private ImageFileUploader mockImageFileUploader;

@Autowired
private JwtProvider jwtProvider;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.notification.service;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.member.model.FavoriteCategory;
import com.tenten.linkhub.domain.member.model.Member;
import com.tenten.linkhub.domain.member.model.ProfileImage;
Expand All @@ -20,20 +21,16 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@ActiveProfiles("test")
@SpringBootTest
@Transactional
public class NotificationServiceTest {
public class NotificationServiceTest extends IntegrationApplicationTest {

@Autowired
private NotificationService notificationService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.space.facade;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.member.model.FavoriteCategory;
import com.tenten.linkhub.domain.member.model.Member;
import com.tenten.linkhub.domain.member.model.ProfileImage;
Expand All @@ -22,20 +23,16 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@ActiveProfiles("test")
@Transactional
@SpringBootTest
class CommentFacadeTest {
class CommentFacadeTest extends IntegrationApplicationTest {

@Autowired
private CommentFacade commentFacade;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.space.facade;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.member.model.FavoriteCategory;
import com.tenten.linkhub.domain.member.model.Member;
import com.tenten.linkhub.domain.member.model.ProfileImage;
Expand Down Expand Up @@ -28,19 +29,15 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;

@ActiveProfiles("test")
@Transactional
@SpringBootTest
class LinkFacadeTest {
class LinkFacadeTest extends IntegrationApplicationTest {

@Autowired
private LinkFacade linkFacade;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.space.facade;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.member.model.FavoriteCategory;
import com.tenten.linkhub.domain.member.model.Member;
import com.tenten.linkhub.domain.member.model.ProfileImage;
Expand All @@ -23,21 +24,16 @@
import com.tenten.linkhub.domain.space.repository.scrap.ScrapRepository;
import com.tenten.linkhub.domain.space.repository.space.SpaceJpaRepository;
import com.tenten.linkhub.domain.space.service.LinkService;
import com.tenten.linkhub.domain.space.service.SpaceService;
import com.tenten.linkhub.domain.space.service.dto.link.LinkCreateRequest;
import com.tenten.linkhub.global.aws.dto.ImageInfo;
import com.tenten.linkhub.global.aws.s3.ImageFileUploader;
import com.tenten.linkhub.global.exception.PolicyViolationException;
import com.tenten.linkhub.global.exception.UnauthorizedAccessException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.BDDMockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
Expand All @@ -48,10 +44,8 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;

@ActiveProfiles("test")
@Transactional
@SpringBootTest
class SpaceFacadeTest {
class SpaceFacadeTest extends IntegrationApplicationTest {

@Autowired
private SpaceFacade spaceFacade;
Expand All @@ -74,9 +68,6 @@ class SpaceFacadeTest {
@Autowired
private ScrapRepository scrapRepository;

@MockBean
private ImageFileUploader mockImageFileUploader;

private Long myMemberId;
private Long anotherMemberId;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.space.facade;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.member.model.FavoriteCategory;
import com.tenten.linkhub.domain.member.model.Member;
import com.tenten.linkhub.domain.member.model.ProfileImage;
Expand All @@ -24,17 +25,13 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@ActiveProfiles("test")
@Transactional
@SpringBootTest
class SpaceInvitationFacadeTest {
class SpaceInvitationFacadeTest extends IntegrationApplicationTest {

@Autowired
private SpaceInvitationFacade spaceInvitationFacade;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.space.service;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.member.model.FavoriteCategory;
import com.tenten.linkhub.domain.member.model.Member;
import com.tenten.linkhub.domain.member.model.ProfileImage;
Expand All @@ -22,19 +23,15 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@ActiveProfiles("test")
@Transactional
@SpringBootTest
class CommentServiceTest {
class CommentServiceTest extends IntegrationApplicationTest {

@Autowired
private CommentService commentService;
Expand Down Expand Up @@ -251,7 +248,7 @@ void createReply_DataNotFoundException() {
.isInstanceOf(DataNotFoundException.class);
}

private void setUpTestData(){
private void setUpTestData() {
Member member1 = new Member(
"testSocialId",
Provider.kakao,
Expand Down Expand Up @@ -297,7 +294,7 @@ private void setUpTestData(){
"두번째 스페이스",
"두번째 스페이스 소개글",
Category.ETC,
new SpaceImage( "https://testimage2", "테스트 이미지2"),
new SpaceImage("https://testimage2", "테스트 이미지2"),
new SpaceMember(setUpMemberId1, Role.OWNER),
true,
false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.space.service;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.member.model.FavoriteCategory;
import com.tenten.linkhub.domain.member.model.Member;
import com.tenten.linkhub.domain.member.model.ProfileImage;
Expand All @@ -25,20 +26,16 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@ActiveProfiles("test")
@SpringBootTest
@Transactional
class DefaultLinkServiceTest {
class DefaultLinkServiceTest extends IntegrationApplicationTest {

@Autowired
private LinkService linkService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.space.service;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.member.model.FavoriteCategory;
import com.tenten.linkhub.domain.member.model.Member;
import com.tenten.linkhub.domain.member.model.ProfileImage;
Expand All @@ -26,21 +27,17 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@ActiveProfiles("test")
@Transactional
@SpringBootTest
class DefaultSpaceServiceTest {
class DefaultSpaceServiceTest extends IntegrationApplicationTest {

@Autowired
private SpaceService spaceService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.space.service;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.member.model.FavoriteCategory;
import com.tenten.linkhub.domain.member.model.Member;
import com.tenten.linkhub.domain.member.model.ProfileImage;
Expand All @@ -23,9 +24,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.ActiveProfiles;

import java.util.List;
import java.util.concurrent.CountDownLatch;
Expand All @@ -35,9 +34,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@ActiveProfiles("test")
@SpringBootTest
class FavoriteServiceTest {
class FavoriteServiceTest extends IntegrationApplicationTest {

@Autowired
private FavoriteService favoriteService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tenten.linkhub.domain.space.service;

import com.tenten.linkhub.IntegrationApplicationTest;
import com.tenten.linkhub.domain.member.model.FavoriteCategory;
import com.tenten.linkhub.domain.member.model.Member;
import com.tenten.linkhub.domain.member.model.ProfileImage;
Expand All @@ -20,8 +21,6 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;

import java.util.List;
Expand All @@ -31,11 +30,9 @@

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
@ActiveProfiles("test")
@Slf4j
@Sql(scripts = "/sql/clean_up.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public class LikeServiceTest {
public class LikeServiceTest extends IntegrationApplicationTest {
private static int THREAD_COUNT = 100;

@Autowired
Expand Down

0 comments on commit 176645a

Please sign in to comment.