Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created July 26, 2020 20:43
Show Gist options
  • Save chelseatroy/9b350562a1bac37b9536373eb8ac4791 to your computer and use it in GitHub Desktop.
Save chelseatroy/9b350562a1bac37b9536373eb8ac4791 to your computer and use it in GitHub Desktop.
Service Integration Test
//
// BlogPostServiceTests.swift
// ScottishGaelicTattooHandbookTests
//
// Created by Chelsea Troy on 7/26/20.
// Copyright © 2020 Chelsea Troy. All rights reserved.
//
import XCTest
@testable import ScottishGaelicTattooHandbook
class BlogPostServiceTests: XCTestCase {
var systemUnderTest: BlogPostService!
override func setUp() {
self.systemUnderTest = BlogPostService()
}
override func tearDown() {
self.systemUnderTest = nil
}
func testAPI_returnsSuccessfulResult() {
//Given
var blogPosts: [BlogPost]!
var error: Error?
let promise = expectation(description: "Completion handler is invoked")
//When
self.systemUnderTest.getBlogPosts(completion: { data, shouldntHappen in
blogPosts = data
error = shouldntHappen
promise.fulfill()
})
wait(for: [promise], timeout: 5)
//Then
XCTAssertNotNil(blogPosts)
XCTAssertEqual(blogPosts.count, 3)
for post in blogPosts {
XCTAssertNotNil(post.title.rendered)
XCTAssertNotNil(post.imageURL)
}
XCTAssertNil(error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment