Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Testes - A que será que se destina?

Testes - A que será que se destina?

Uma talk baseada em exemplos reais de implementações de testes, a partir de experências práticas e conceitos teóricos. Os objetivos são: encorajar a implementação da cultura de testes; Para aqueles que já o fazem, aprimorar a qualidade de testes implantados; E que o conteúdo apresentado seja orientador para os que se interessem pelo tema.

Ronan Rodrigo Nunes

November 09, 2019
Tweet

More Decks by Ronan Rodrigo Nunes

Other Decks in Programming

Transcript

  1. Testes: A que será que se destina? Breve história sobre

    testes, boas e más práticas no ecossistema Apple Ronan Rodrigo Nunes
  2. func test_primaryButtonTapped_doesRouteToFullSheet() { // given XCTAssertTrue(router.routeToFullSheetCallCount == 0) // when

    interactor.primaryButtonTapped() // then XCTAssertTrue(router.routeToFullSheetCallCount == 1) } ✘
  3. func test_allByMonth_existingMonth_callCompletionWithItems() { var expectedGroupedFoods: [GroupedFoods]? // ... guard let

    expectedGroupedFoods = expectedGroupedFoods, firstGroup = expectedGroupedFoods.first else { XCTFail("empty expectedGroupedFoods") } XCTAssertFalse(firstGroup.foods.isEmpty) } ✘
  4. func test_allByMonth_existingMonth_callCompletionWithItems() { var expectedGroupedFoods: [GroupedFoods]? // ... if let

    expectedGroupedFoods = expectedGroupedFoods { if let firstGroup = expectedGroupedFoods.first { XCTAssertFalse(firstGroup.foods.isEmpty) } } } ✘
  5. func test_allByMonth_existingMonth_callCompletionWithItems() { var expectedGroupedFoods: [GroupedFoods]? let month = MonthGatewayFactory.make().month(number:

    1) gateway.all(byMonth: month) { expectedGroupedFoods = $0.data } XCTAssertEqual(expectedGroupedFoods?.isEmpty, false) } ✘
  6. func test_allByMonth_existingMonth_callCompletionWithItems() { var expectedGroupedFoods: [GroupedFoods]? let month = MonthGatewayFactory.make().month(number:

    1) gateway.all(byMonth: month) { expectedGroupedFoods = $0.data } XCTAssertEqual(expectedGroupedFoods?.isEmpty, false) } ✔
  7. func test_finishReport_completeFlow() { var completed = false interactor.waitForCompletion().subscribe { _

    in completed = true } .disposed(by: disposeBag) interactor.finish() XCTAssertTrue(completed) } ✘
  8. func test_finishReport_completeFlow() { var completed = false onCompleteFlow(completed = true)

    interactor.finish() XCTAssertTrue(completed) } func onCompleteFlow(_ fn: @escaping @autoclosure () -> ()) { interactor.waitForCompletion() .subscribe { _ in fn() } .disposeOnTearDown(testCase: self) } ✔
  9. class ReportTripInteractorTests: XCTestCase class ReportTripInteractor_StartTripTests: ReportTripInteractorTests class ReportTripInteractor_FinishingTripTests: ReportTripInteractorTests class

    ReportTripInteractor_SearchingTripTests: ReportTripInteractorTests class ReportTripInteractor_WaintingTripTests: ReportTripInteractorTests ✔
  10. func test_start_validInteractor_createEventAtStream() { let expectedResponse = Response(uuid: "id") shareService.fetchHandler =

    { _ in .just(expectedResponse) } worker.start(interactor) someStream.dataSubject .subscribe(onNext: { eventResponse in XCTAssertEqual(expectedResponse, eventResponse) }) .disposed(by: disposeBag) } ✘
  11. func test_start_validInteractor_createEventAtStream() { let expectedResponse = Response(uuid: "id") shareService.fetchHandler =

    { _ in .just(expectedResponse) } var eventResponse: Response? someStream.dataSubject .subscribe(onNext: { eventResponse = $0 }) .disposed(by: disposeBag) worker.start(interactor) XCTAssertEqual(expectedResponse, eventResponse) } ✔
  12. final class ListFoodPresenterViewControllerTests: XCTestCase { private let bindable: ListFoodTableViewControllerBindMock! private

    let presenter: ListFoodPresenterViewController! override func setUp() { super.setUp() bindable = ListFoodTableViewControllerBindMock() presenter = ListFoodPresenterViewController() presenter.bindable = bindable } } !
  13. final class ListFoodPresenterViewControllerTests: XCTestCase { private let bindable = ListFoodTableViewControllerBindMock()

    private let presenter = ListFoodPresenterViewController() override func setUp() { super.setUp() presenter.bindable = bindable } } ✔
  14. final class ListFoodPresenterViewControllerTests: XCTestCase { private let bindable = ListFoodTableViewControllerBindMock()

    private lazy var presenter: ListFoodPresenterViewController = { let presenter = ListFoodPresenterViewController() presenter.bindable = bindable return presenter }() } ✔