Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vermont42 committed Apr 24, 2019
1 parent e3628e7 commit 76ece1f
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 10 deletions.
24 changes: 24 additions & 0 deletions Conjugar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

/* Begin PBXBuildFile section */
035C646F22299A7E001ECC02 /* RatingsFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035C646E22299A7E001ECC02 /* RatingsFetcher.swift */; };
038E03132270A868005CFC96 /* IntExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E03122270A868005CFC96 /* IntExtensionTests.swift */; };
038E03152270A9FB005CFC96 /* TestGameCenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E03142270A9FB005CFC96 /* TestGameCenterTests.swift */; };
038E03182270AC01005CFC96 /* DeviceUtilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E03172270AC01005CFC96 /* DeviceUtilityTests.swift */; };
038E031A22711B76005CFC96 /* UIViewControllerExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E031922711B76005CFC96 /* UIViewControllerExtensionTests.swift */; };
E10178021F3F753400F0BC97 /* UIViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E10178011F3F753400F0BC97 /* UIViewExtensions.swift */; };
E107B08B1EB66CE6004C5E91 /* verbs.xml in Resources */ = {isa = PBXBuildFile; fileRef = E107B08A1EB66CE6004C5E91 /* verbs.xml */; };
E107B0921EB66F28004C5E91 /* VerbParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = E107B0911EB66F28004C5E91 /* VerbParser.swift */; };
Expand Down Expand Up @@ -143,6 +147,10 @@

/* Begin PBXFileReference section */
035C646E22299A7E001ECC02 /* RatingsFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RatingsFetcher.swift; sourceTree = "<group>"; };
038E03122270A868005CFC96 /* IntExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntExtensionTests.swift; sourceTree = "<group>"; };
038E03142270A9FB005CFC96 /* TestGameCenterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestGameCenterTests.swift; sourceTree = "<group>"; };
038E03172270AC01005CFC96 /* DeviceUtilityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceUtilityTests.swift; sourceTree = "<group>"; };
038E031922711B76005CFC96 /* UIViewControllerExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewControllerExtensionTests.swift; sourceTree = "<group>"; };
E10178011F3F753400F0BC97 /* UIViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewExtensions.swift; sourceTree = "<group>"; };
E107B08A1EB66CE6004C5E91 /* verbs.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = verbs.xml; sourceTree = "<group>"; };
E107B0911EB66F28004C5E91 /* VerbParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerbParser.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -275,6 +283,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
038E03162270ABEA005CFC96 /* Analytics */ = {
isa = PBXGroup;
children = (
038E03172270AC01005CFC96 /* DeviceUtilityTests.swift */,
);
path = Analytics;
sourceTree = "<group>";
};
E107B08C1EB66E16004C5E91 /* Views */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -390,6 +406,9 @@
isa = PBXGroup;
children = (
E151223021A62AE9008EF307 /* ReviewPrompterTests.swift */,
038E03122270A868005CFC96 /* IntExtensionTests.swift */,
038E03142270A9FB005CFC96 /* TestGameCenterTests.swift */,
038E031922711B76005CFC96 /* UIViewControllerExtensionTests.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -490,6 +509,7 @@
E1F06AEB1E8F05F400ADD2E1 /* ConjugarTests */ = {
isa = PBXGroup;
children = (
038E03162270ABEA005CFC96 /* Analytics */,
E15D3BED1F532E8E003771BB /* Controllers */,
E15D3BF41F53397A003771BB /* Helpers */,
E198F9031F5D7C6B00BAF553 /* Models */,
Expand Down Expand Up @@ -806,7 +826,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
038E03182270AC01005CFC96 /* DeviceUtilityTests.swift in Sources */,
E12D06A31F5E85A200CDD54E /* VerbCellTests.swift in Sources */,
038E031A22711B76005CFC96 /* UIViewControllerExtensionTests.swift in Sources */,
038E03132270A868005CFC96 /* IntExtensionTests.swift in Sources */,
E151223121A62AE9008EF307 /* ReviewPrompterTests.swift in Sources */,
E1DC939521B5836400DD4048 /* QuizTests.swift in Sources */,
E198F9051F5D7CB200BAF553 /* ConjugatorTests.swift in Sources */,
Expand All @@ -815,6 +838,7 @@
E14589F61F5B7E9D00EEF141 /* VerbVCTests.swift in Sources */,
E15D3BF61F533997003771BB /* MockNavigationC.swift in Sources */,
E198F9021F5D79F100BAF553 /* VerbViewTests.swift in Sources */,
038E03152270A9FB005CFC96 /* TestGameCenterTests.swift in Sources */,
E1F06AED1E8F05F400ADD2E1 /* MainTabBarVCTests.swift in Sources */,
E15D3BF11F532F4E003771BB /* BrowseVerbsVCTests.swift in Sources */,
);
Expand Down
2 changes: 1 addition & 1 deletion Conjugar/BrowseInfoVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BrowseInfoVC: UIViewController, UITableViewDelegate, UITableViewDataSource
if let castedView = view as? BrowseInfoView {
return castedView
} else {
fatalError(fatalCastMessage(viewController: BrowseInfoVC.self, view: BrowseInfoView.self))
fatalError(fatalCastMessage(view: BrowseInfoView.self))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Conjugar/BrowseVerbsVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BrowseVerbsVC: UIViewController, UITableViewDelegate, UITableViewDataSourc
if let castedView = view as? BrowseVerbsView {
return castedView
} else {
fatalError(fatalCastMessage(viewController: BrowseVerbsVC.self, view: BrowseVerbsView.self))
fatalError(fatalCastMessage(view: BrowseVerbsView.self))
}
}

Expand Down
1 change: 0 additions & 1 deletion Conjugar/DeviceUtility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public extension UIDevice {
case "AppleTV6,2": return "Apple TV 4K"
case "AudioAccessory1,1": return "HomePod"
case "i386", "x86_64": return "Simulator"
//case "i386", "x86_64": return "iPhone SE"
default: return identifier
}
}
Expand Down
2 changes: 1 addition & 1 deletion Conjugar/InfoVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class InfoVC: UIViewController, UITextViewDelegate {
if let castedView = view as? InfoView {
return castedView
} else {
fatalError(fatalCastMessage(viewController: InfoVC.self, view: InfoView.self))
fatalError(fatalCastMessage(view: InfoView.self))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Conjugar/QuizVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class QuizVC: UIViewController, UITextFieldDelegate, QuizDelegate {
if let castedView = view as? QuizView {
return castedView
} else {
fatalError(fatalCastMessage(viewController: QuizVC.self, view: QuizView.self))
fatalError(fatalCastMessage(view: QuizView.self))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Conjugar/ResultsVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ResultsVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
if let castedView = view as? ResultsView {
return castedView
} else {
fatalError(fatalCastMessage(viewController: ResultsVC.self, view: ResultsView.self))
fatalError(fatalCastMessage(view: ResultsView.self))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Conjugar/SettingsVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SettingsVC: UIViewController {
if let castedView = view as? SettingsView {
return castedView
} else {
fatalError(fatalCastMessage(viewController: SettingsVC.self, view: SettingsView.self))
fatalError(fatalCastMessage(view: SettingsView.self))
}
}

Expand Down
4 changes: 2 additions & 2 deletions Conjugar/UIViewControllerExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

extension UIViewController {
func fatalCastMessage(viewController: Any, view: Any) -> String {
return "Could not cast \(viewController).view to \(view)."
func fatalCastMessage(view: Any) -> String {
return "Could not cast \(self).view to \(view)."
}
}
2 changes: 1 addition & 1 deletion Conjugar/VerbVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class VerbVC: UIViewController {
if let castedView = view as? VerbView {
return castedView
} else {
fatalError(fatalCastMessage(viewController: VerbVC.self, view: VerbView.self))
fatalError(fatalCastMessage(view: VerbView.self))
}
}

Expand Down
17 changes: 17 additions & 0 deletions ConjugarTests/Analytics/DeviceUtilityTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// DeviceUtilityTests.swift
// ConjugarTests
//
// Created by Joshua Adams on 4/24/19.
// Copyright © 2019 Josh Adams. All rights reserved.
//

import XCTest
@testable import Conjugar

class DeviceUtilityTests: XCTestCase {
func testModelName() {
// This won't work if tests run on device. But in my case, they don't.
XCTAssertEqual(UIDevice.current.modelName, "Simulator")
}
}
27 changes: 27 additions & 0 deletions ConjugarTests/Utils/IntExtensionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// IntExtensionTests.swift
// ConjugarTests
//
// Created by Joshua Adams on 4/24/19.
// Copyright © 2019 Josh Adams. All rights reserved.
//

import XCTest
@testable import Conjugar

class IntExtensionTests: XCTestCase {
func testShort() {
let time = 42
XCTAssertEqual(time.timeString, "42")
}

func testMedium() {
let time = 142
XCTAssertEqual(time.timeString, "2:22")
}

func testLong() {
let time = 3601
XCTAssertEqual(time.timeString, "1:00:01")
}
}
38 changes: 38 additions & 0 deletions ConjugarTests/Utils/TestGameCenterTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// TestGameCenterTests.swift
// ConjugarTests
//
// Created by Joshua Adams on 4/24/19.
// Copyright © 2019 Josh Adams. All rights reserved.
//

import XCTest
@testable import Conjugar

class TestGameCenterTests: XCTestCase {
private let analytics = TestAnalyticsService()

func testAuthenticate() {
let tgc = TestGameCenter(isAuthenticated: false)

tgc.authenticate(analyticsService: analytics, completion: { didAuthenticate in
XCTAssert(didAuthenticate)

tgc.authenticate(analyticsService: self.analytics, completion: { didAuthenticate in
XCTAssertFalse(didAuthenticate)
})
})
}

func testReportScore() {
// Nothing to test. Exercising for coverage.
let tgc = TestGameCenter()
tgc.reportScore(42)
}

func testShowLeaderboard() {
// Nothing to test. Exercising for coverage.
let tgc = TestGameCenter()
tgc.showLeaderboard()
}
}
21 changes: 21 additions & 0 deletions ConjugarTests/Utils/UIViewControllerExtensionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// UIViewControllerExtensionTests.swift
// ConjugarTests
//
// Created by Joshua Adams on 4/24/19.
// Copyright © 2019 Josh Adams. All rights reserved.
//

import XCTest
import UIKit
@testable import Conjugar

class UIViewControllerExtensionTests: XCTestCase {
func testFatalCastMessage() {
let vc = VerbVC()
let view = VerbView()
let message = vc.fatalCastMessage(view: view.self)
XCTAssert(message.contains("Could not cast <Conjugar.VerbVC:"))
XCTAssert(message.contains("to <Conjugar.VerbView:"))
}
}

0 comments on commit 76ece1f

Please sign in to comment.