[TIL] 21.04.03.(Sat)

Ryan (Geonhee) Son·2021년 4월 4일
0

활동 내용

  • 계산기 프로젝트 Step 1 PR

프로젝트 수행 시 고민했던 점

  • 어떤 단위로 프로토콜를 작성할 것인가 (추상화 단위)
  • 유닛테스트에서 throw하는 에러를 확인하는 방법 - XCTAssertThrowsError(_:_:_:)
  • 유닛테스트의 단위
  • 최대표시숫자 9자리수로 제한하기
  • 에러처리 방법

조언을 얻고 싶은 부분

  • 예외처리할 때 에러를 throw하는 방법으로만 처리하고 있는데 더 좋은 방법이 있을까요?
  • 현업에서는 페어프로그래밍을 어떻게하는지 (우리는 줌으로 했는데) 궁금합니다.
  • 전체 테스트를 수행할 때 testExample 메소드를 통해 개별 test 메소드들을 호출하는 과정에서
  • 각 개별테스트 시작시 초기화를 위해 인스턴스를 매번 만들어줬는데 이 작업이 너무 반복되는 느낌입니다. 인스턴스를 한번만 만들어서 이용하고 싶은데 testExample에서 개별테스트들이 서로 간섭받지 않으려면 어떻게 해야할까요?
import XCTest
@testable import Calculator
class StackTests: XCTestCase {
    
    var stackDecimalTest = Stack<Double>()
    var stackBinaryTest = Stack<Int>()
    
    override func setUpWithError() throws {
        try super.setUpWithError()
    }
    
    override func tearDownWithError() throws {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }
    
    func testExample() throws {
        test_stack_pop()
        test_stack_pop_error()
        test_stack_top()
        test_stack_isEmpty()
    }
    
    func test_stack_pop() {
        stackDecimalTest = Stack<Double>(list:[1, 2])
        XCTAssertEqual(try stackDecimalTest.pop(), 2)
    }
    
    func test_stack_pop_error() {
        stackDecimalTest = Stack<Double>()
        XCTAssertThrowsError(try stackDecimalTest.pop()) { (error) in
            XCTAssertEqual(error as! StackError, StackError.poppedItemIsNil)
        }
    }
    
    func test_stack_top() {
        stackDecimalTest = Stack<Double>(list:[1, 2])
        XCTAssertEqual(try stackDecimalTest.top(), 2)
    }
    
    func test_stack_isEmpty() {
        stackDecimalTest = Stack<Double>()
        XCTAssertEqual(stackDecimalTest.isEmpty, true)
    }
}
profile
합리적인 해법 찾기를 좋아합니다.

0개의 댓글