Skip to content

Conversation

@ParkSeongGeun
Copy link
Collaborator

📌 관련 이슈 번호 ex) #이슈번호


📘 작업 유형

  • 테스트

📙 작업 내역 (구현 내용 및 작업 내역을 기재합니다.)

테스트 결과

image

📝 특이 사항 (Optional)

  • Lottie를 PresentationTests를 타겟으로 설치를 진행했습니다.

    • Presentation Test를 위함입니다.
  • PresentationTests의 설정을 변경하였습니다.

    • iphone, minimum deployment 수정
  • 기존 RecordManager로 테스트를 진행하면, 아래와 같은 에러가 출력됩니다.

    'required condition is false: format.sampleRate == hwFormat.sampleRate'
    
    • 이는 AVAudioEngine 관련 문제로, 테스트 환경에서 오디오 설정이 제대로 이루어지지 않아 발생합니다. (이것때문에 많은 시간을 쏟았네요..)
  • 위의 문제를 해결하기 위해 테스트용 Mock 객체를 만들어 실제 오디오 기능을 대체하는 방안을 적용해보려고 하였습니다.

    • RecordManager의 추상화를 진행한 뒤 MockRecordManager를 생성하여, RecordViewModel 테스트를 진행했습니다.

Copy link
Member

@Hansangjin98 Hansangjin98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~!

Comment on lines -13 to +14
final class RecordManager {
public protocol RecordManagerProtocol {
var recognizedText: String { get }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 저희 네이밍 컨벤션과 다른 것 같습니다!
  2. minuteAndSeconds가 추상화가 필요한 변수일까요?

Comment on lines +24 to 26

public final class DefaultRecordManager: RecordManagerProtocol {
// MARK: - 음성 인식을 위한 Properties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RecordManager는 코드 품질을 개선할 여지가 많은 것 같습니다.
추후에 여유가 되신다면 도전해보셔도 좋을 것 같네요!

Comment on lines +29 to +36
func test_givenNewViewModel_whenInitialized_thenStateIsCorrectlySet() {
// Then
XCTAssertFalse(viewModel.state.isRecording)
XCTAssertFalse(viewModel.state.canMoveToNext)
XCTAssertEqual(viewModel.state.timeText, "00:00")
XCTAssertFalse(viewModel.state.isErrorPresent)
XCTAssertTrue(viewModel.state.isAuthorized)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개인적으로 테스트 시나리오의 직관성이 조금 아쉽다는 생각이 듭니다.
ViewModel이 초기화되었을 때 상태값이 올바르게 설정되는지 테스트하는 것 같은데, 명시적으로 ViewModel을 초기화 시키는 코드와 어떤 값으로 초기화가 되어야 하는지 비교 객체를 선언해주시는 건 어떨까요?

Comment on lines +113 to +135
// MARK: - Complete Recording Flow Test
func test_GivenInitialState_WhenPerformRecordingSequence_ThenStateTransitionsCorrectly() async {
// Given
XCTAssertFalse(viewModel.state.isRecording)
XCTAssertFalse(viewModel.state.canMoveToNext)

// When
viewModel.action(.startRecording)

// Then
XCTAssertTrue(mockRecordManager.setupSpeechCalled)
XCTAssertTrue(mockRecordManager.startRecordingCalled)
XCTAssertTrue(viewModel.state.isRecording)
XCTAssertFalse(viewModel.state.canMoveToNext)

// When
viewModel.action(.stopRecording)

// Then
XCTAssertTrue(mockRecordManager.stopRecordingCalled)
XCTAssertFalse(viewModel.state.isRecording)
XCTAssertTrue(viewModel.state.canMoveToNext)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RecordViewModel의 모든 흐름을 한번에 테스트하는 것 같은데요,
유닛테스트의 의의와 원칙을 다시 한번 고민해보시면 좋을 것 같습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📐 Test 테스트

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants