Skip to content
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

Feature/unit tests #764

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import XCTest
@testable import NetworkInfrastructure

class AccessTokenTests: XCTestCase {
final class AccessTokenTests: XCTestCase {

func testMissingAccounIdFromResponse() throws {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import XCTest
@testable import NetworkInfrastructure

class AddToWatchlistTests: XCTestCase {
final class AddToWatchlistTests: XCTestCase {

func testMissingStatusCodeFromResponse() throws {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// MockURLSession.swift
// NetworkInfrastructure-Unit-NetworkInfrastructureTests
//
// Created by Alonso on 21/08/23.
//

import Foundation

final class MockURLSession: URLSession {

var dataTaskWithRequestCompletionHandler: (Data?, URLResponse?, Error?) = (nil, nil, nil)
var dataTaskWithRequestResult = MockURLSessionDataTask()
private(set) var dataTaskWithRequestCallCount = 0
override func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask {
dataTaskWithRequestCallCount += 1
completionHandler(dataTaskWithRequestCompletionHandler.0,
dataTaskWithRequestCompletionHandler.1,
dataTaskWithRequestCompletionHandler.2)
return dataTaskWithRequestResult
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MockURLSessionDataTask.swift
// NetworkInfrastructure-Unit-NetworkInfrastructureTests
//
// Created by Alonso on 21/08/23.
//

import Foundation

final class MockURLSessionDataTask: URLSessionDataTask {

private(set) var resumeCallCount = 0
override func resume() {
resumeCallCount += 1
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import XCTest
@testable import NetworkInfrastructure

class MarkAsFavoriteTests: XCTestCase {
final class MarkAsFavoriteTests: XCTestCase {

func testMissingStatusCodeFromResponse() throws {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import XCTest
@testable import NetworkInfrastructure

class MovieCreditsTests: XCTestCase {
final class MovieCreditsTests: XCTestCase {

// MARK: - Cast tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import XCTest
@testable import NetworkInfrastructure

class MovieGenreTests: XCTestCase {
final class MovieGenreTests: XCTestCase {

func testMissingIdFromResponse() throws {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import XCTest
@testable import NetworkInfrastructure

class MovieImagesConfigurationTests: XCTestCase {
final class MovieImagesConfigurationTests: XCTestCase {

func testMissingBaseURLStringFromResponse() throws {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import XCTest
@testable import NetworkInfrastructure

class MovieResultPaginationTests: XCTestCase {
final class MovieResultPaginationTests: XCTestCase {

var movieResultUnderTest: MovieResult!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import XCTest
@testable import NetworkInfrastructure

class MovieReviewTests: XCTestCase {
final class MovieReviewTests: XCTestCase {

func testMissingIdFromResponse() throws {
// Arrange
Expand Down
35 changes: 35 additions & 0 deletions NetworkInfrastructure/Services/MovieClientTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// MovieClientTests.swift
// NetworkInfrastructure-Unit-NetworkInfrastructureTests
//
// Created by Alonso on 21/08/23.
//

import XCTest

final class MovieClientTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

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 {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
Loading