-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FetchRecipeDeatil의 비즈니스 로직을 테스트 해보았습니다. #16
Conversation
extension Recipe { | ||
|
||
static func dummy() -> Recipe { | ||
.init(id: 1, type: .coffee, name: "", description: "", writer: .init(id: 1, profileImage: "", nickname: "", createdAt: Date()), imageUrls: [], isLikedByCurrentUser: false, likeCount: 0, createdAt: Date()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
라인수가 길어지는 경우, 줄바꿈 해주세요.
또 이런 init 단계에 파라미터를 넣어주는 코드 같은 경우에는 언제든지 확장되어 길어질 수 있으니 줄바꿈을 하면서 작성하는게 좋아요. 앞으로 줄바꿈 같은 코드 스타일 코멘트는 줄여나가도록 더 신경써주시면 좋을 것 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[d7ab88c] 수정했습니다
class FetchRecipeDetailUseCaseMock: FetchRecipeDetailUseCase { | ||
var executeCallCount: Int = 0 | ||
var executeStub: Single<Result<Recipe, Error>> = .just(.failure(NSError())) | ||
func execute(recipeID: Int) -> Single<Result<Recipe, Error>> { | ||
executeCallCount += 1 | ||
return executeStub | ||
} | ||
} | ||
|
||
class RecipeDetailInteractorDelegateMock: RecipeDetailInteractorDelegate { | ||
var fetchedCallCount: Int = 0 | ||
var fetchedRecipeResult: Result<Recipe, Error>? | ||
func fetchedRecipe(result: Result<Recipe, Error>) { | ||
fetchedCallCount += 1 | ||
fetchedRecipeResult = result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
얘네는 final class로 선언하시지 않은 이유가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final 처리가 아직 익숙하지 않아서 놓친거 같습니다
좀 더 신경 쓰도록 하겠습니다
[415e9a4] 수정했습니다.
override func tearDownWithError() throws { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
불필요한 메서드는 제거해주세요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[18959c6] 제거했습니다.
|
||
extension RecipeDetailInteractorTests { | ||
|
||
func test_화면이_로드될때_FetchRecipeDetailUsecase를_실행합니다() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FetchRecipeDetailUseCase를 실행하는게 아니라 FetchRecipeDetailUseCase의 execute를 호출하는거 아닐까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[0cc06c1] 네이밍 수정했습니다
func test_FetchRecipeDetailUsecase의_성공응답이오면_Delegate로_성공을_전달합니다() { | ||
// given | ||
let interactor = createInteractor() | ||
let recipe = Recipe.dummy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dummyRecipe로 네이밍하는게 더 명확하지 않을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[80597bd] 수정했습니다
XCTAssertEqual(self.fetchRecipeDetailUsecase.executeCallCount, 1) | ||
XCTAssertEqual(self.delegate.fetchedCallCount, 1) | ||
|
||
if case .success(let fetchedRecipe)? = self.delegate.fetchedRecipeResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기에는 self 필요 없을 것 같은데 확인부탁드려요~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[7e579b8] 수정했습니다
XCTAssertEqual(self.fetchRecipeDetailUsecase.executeCallCount, 1) | ||
XCTAssertEqual(self.delegate.fetchedCallCount, 1) | ||
|
||
if case .failure(let fetchedError as NSError) = self.delegate.fetchedRecipeResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기에는 self 필요 없을 것 같은데 확인부탁드려요~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[7e579b8] 수정했습니다
var fetchRecipeDetailRepository: FetchRecipeRepositoryMock! | ||
var disposeBag: DisposeBag! | ||
|
||
class FetchRecipeRepositoryMock: RecipeDetailRepository { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final class 고민 부탁해요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[415e9a4] 수정했습니다
} | ||
|
||
func createUseCase() -> FetchRecipeDetailUseCase { | ||
let usecase = FetchRecipeDetailUseCaseImpl(repository: fetchRecipeDetailRepository) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개행부탁합니다~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[d0d27b0] 수정했습니다
override func tearDownWithError() throws { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안쓰면 제거해주세요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[18959c6] 제거 했습니다
|
||
extension FetchRecipeDetailUseCaseTests { | ||
|
||
func test_execute를_호출하면_1번_RecipeDetailRepository의_fetchRecipeDetail을_호출합니다(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 테스트 코드에서 1번 호출하는건 검증하고 있지 않은 것 같네요?
여러번 호출해도 1번만 calleCount가 올라가는지 검증해야 테스트 케이스와 맞겠네요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정하겠습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[61854b3] 수정했습니다
.subscribe(onSuccess: { result in | ||
if case .failure(let receivedError as NSError) = result { | ||
// Then | ||
|
||
XCTAssertEqual(receivedError.domain, error.domain) | ||
XCTAssertEqual(receivedError.code, error.code) | ||
expectation.fulfill() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
질문) onSuccess 내부에서 failure 검증이 성공했나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
execute에서 .success로 failure를 전달하나보네요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 맞습니다
Quality Gate passedIssues Measures |
FetchRecipeDetailUseCaseTests를 생성하였습니다
RecipeDetailInteractorTests를 생성하였습니다