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 25, 2019
1 parent 1b4ac9f commit e20b949
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 58 deletions.
4 changes: 4 additions & 0 deletions Conjugar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 */; };
038E031C2271E239005CFC96 /* AnalyticsServiceableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038E031B2271E239005CFC96 /* AnalyticsServiceableTests.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 @@ -151,6 +152,7 @@
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>"; };
038E031B2271E239005CFC96 /* AnalyticsServiceableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsServiceableTests.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 @@ -287,6 +289,7 @@
isa = PBXGroup;
children = (
038E03172270AC01005CFC96 /* DeviceUtilityTests.swift */,
038E031B2271E239005CFC96 /* AnalyticsServiceableTests.swift */,
);
path = Analytics;
sourceTree = "<group>";
Expand Down Expand Up @@ -836,6 +839,7 @@
E1EC70F22198A10B00872787 /* UIViewControllerExtension.swift in Sources */,
E14589F41F5B7BB000EEF141 /* BrowseInfoVCTests.swift in Sources */,
E14589F61F5B7E9D00EEF141 /* VerbVCTests.swift in Sources */,
038E031C2271E239005CFC96 /* AnalyticsServiceableTests.swift in Sources */,
E15D3BF61F533997003771BB /* MockNavigationC.swift in Sources */,
E198F9021F5D79F100BAF553 /* VerbViewTests.swift in Sources */,
038E03152270A9FB005CFC96 /* TestGameCenterTests.swift in Sources */,
Expand Down
39 changes: 33 additions & 6 deletions Conjugar/AnalyticsServiceable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ protocol AnalyticsServiceable {
func recordQuizStart()
func recordQuizCompletion(score: Int)
func recordGameCenterAuth()

var visited: String { get }
var viewContröller: String { get }
var quizStart: String { get }
var quizCompletion: String { get }
var scöre: String { get }
var gameCenterAuth: String { get }
}

extension AnalyticsServiceable {
Expand All @@ -23,22 +30,42 @@ extension AnalyticsServiceable {
}

func recordVisitation(viewController: String) {
let visited = "visited"
recordEvent(visited, parameters: ["viewController": "\(viewController)"], metrics: nil)
recordEvent(visited, parameters: [viewContröller: "\(viewController)"], metrics: nil)
}

func recordQuizStart() {
let quizStart = "quizStart"
recordEvent(quizStart)
}

func recordQuizCompletion(score: Int) {
let quizCompletion = "quizCompletion"
recordEvent(quizCompletion, parameters: ["score": "\(score)"], metrics: nil)
recordEvent(quizCompletion, parameters: [scöre: "\(score)"], metrics: nil)
}

func recordGameCenterAuth() {
let gameCenterAuth = "gameCenterAuth"
recordEvent(gameCenterAuth)
}

var visited: String {
return "visited"
}

var viewContröller: String {
return "viewController"
}

var quizStart: String {
return "quizStart"
}

var quizCompletion: String {
return "quizCompletion"
}

var scöre: String {
return "score"
}

var gameCenterAuth: String {
return "gameCenterAuth"
}
}
77 changes: 77 additions & 0 deletions ConjugarTests/Analytics/AnalyticsServiceableTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// AnalyticsServiceableTests.swift
// ConjugarTests
//
// Created by Joshua Adams on 4/25/19.
// Copyright © 2019 Josh Adams. All rights reserved.
//

import XCTest
@testable import Conjugar

class AnalyticsServiceableTests: XCTestCase {
var analytics: [String] = []
var service: TestAnalyticsService?
private let nilServiceMessage = "TestAnalyticsService was nil."

override func setUp() {
super.setUp()
analytics = []
service = TestAnalyticsService(fire: { event in
self.analytics.append(event)
})
}

func testRecordEvent() {
guard let service = service else {
XCTFail(nilServiceMessage)
return
}
let 🥥 = "🥥"
XCTAssertFalse(analytics.contains(🥥))
service.recordEvent(🥥)
XCTAssert(analytics.contains(🥥))
}

func testRecordVisitation() {
guard let service = service else {
XCTFail(nilServiceMessage)
return
}
let pizzaViewController = "PizzaViewController"
XCTAssertFalse(analytics.contains("\(service.visited) \(pizzaViewController)"))
service.recordVisitation(viewController: pizzaViewController)
XCTAssert(analytics.contains("\(service.visited) \(service.viewContröller): \(pizzaViewController) "))
}

func testRecordQuizStart() {
guard let service = service else {
XCTFail(nilServiceMessage)
return
}
XCTAssertFalse(analytics.contains(service.quizStart))
service.recordQuizStart()
XCTAssert(analytics.contains(service.quizStart))
}

func testRecordQuizCompletion() {
guard let service = service else {
XCTFail(nilServiceMessage)
return
}
let score = 42
XCTAssertFalse(analytics.contains("\(service.quizCompletion) \(service.scöre): \(score) "))
service.recordQuizCompletion(score: score)
XCTAssert(analytics.contains("\(service.quizCompletion) \(service.scöre): \(score) "))
}

func testRecordGameCenterAuth() {
guard let service = service else {
XCTFail(nilServiceMessage)
return
}
XCTAssertFalse(analytics.contains("\(service.gameCenterAuth)"))
service.recordGameCenterAuth()
XCTAssert(analytics.contains("\(service.gameCenterAuth)"))
}
}
104 changes: 52 additions & 52 deletions ConjugarUITests/QuizVCUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,55 @@
// Copyright © 2018 Josh Adams. All rights reserved.
//

//import XCTest
//
//class QuizVCUITests: XCTestCase {
// let enableUiTesting = "enable-ui-testing"
//
// override func setUp() {
// continueAfterFailure = false
// }
//
// override func tearDown() {}
//
// func testDifficultSpainQuiz() {
// testQuiz(answers: ["sintiendo", "midiendo", "caminando", "existiendo", "bebiendo", "andas", "ocurre", "leemos", "vais", "duermen", "hago", "fuiste", "dio", "pusimos", "trabajastéis", "recibieron", "aprendí", "ibas", "veía", "caminábamos", "andabais", "sabrán", "cabré", "trabajarás", "estudiará", "escucharíamos", "visitaríais", "podrían", "vaya", "hayas", "sepa", "estudiemos", "permitáis", "comprendan", "pudiera", "viajases", "estuviere", "enseñáremos", "ve", "llevad", "no llegen", "he cubierto", "hubiste bailado", "había dicho", "habremos nadado", "habríais escrito", "hayan cocinado", "hubiera hecho", "hubieses charlado", "hubiere muerto"], region: "Spain", difficulty: "Difficult")
// }
//
// func testDifficultLatinAmericaQuiz() {
// testQuiz(answers: ["sintiendo", "midiendo", "caminando", "existiendo", "bebiendo", "andas", "ocurre", "leemos", "van", "duermo", "haces", "fue", "dimos", "pusieron", "trabajé", "recibiste", "aprendió", "ibamos", "veían", "caminaba", "andabas", "sabrá", "cabremos", "trabajarán", "estudiaré", "escucharías", "visitaría", "podríamos", "vayan", "haya", "sepas", "estudie", "permitamos", "comprendan", "pudiera", "viajases", "estuviere", "enseñáremos", "ve", "lleven", "no llege", "hemos cubierto", "hubieron bailado", "había dicho", "habrás nadado", "habría escrito", "hayamos cocinado", "hubieran hecho", "hubiese charlado", "hubieres muerto"], region: "Latin America", difficulty: "Difficult")
// }
//
// func testModerateSpainQuiz() {
// testQuiz(answers: ["caminas", "anda", "existimos", "bebéis", "van", "duermo", "haces", "muere", "sabremos", "cabréis", "podrán", "caminaré", "andarás", "querría", "pondríamos", "tendríais", "trabajarían", "estudiaría", "has cubierto", "ha dicho", "hemos escrito", "habéis escuchado", "han visitado", "iba", "veías", "era", "viajábamos", "enseñabais", "llevaban", "fui", "diste", "puso", "trabajamos", "ocurristeis", "leieron", "vaya", "hayas", "sepa", "llegemos", "bailéis", "sintiendo", "midiendo", "nadando", "cocinando", "ve", "he", "charlen", "platice", "no lloremos", "no esperéis"], region: "Spain", difficulty: "Moderate")
// }
//
// func testModerateLatinAmericaQuiz() {
// testQuiz(answers: ["caminas", "anda", "existimos", "beben", "voy", "duermes", "hace", "morimos", "sabrán", "cabré", "podrás", "caminará", "andaremos", "querrían", "pondría", "tendrías", "trabajaría", "estudiaríamos", "han cubierto", "he dicho", "has escrito", "ha escuchado", "hemos visitado", "iban", "veía", "eras", "viajaba", "enseñábamos", "llevaban", "fui", "diste", "puso", "trabajamos", "ocurrieron", "leí", "vayas", "haya", "sepamos", "llegen", "baile", "sintiendo", "midiendo", "nadando", "cocinando", "ve", "he", "charle", "platicemos", "no lloren", "no espere"], region: "Latin America", difficulty: "Moderate")
// }
//
// func testEasySpainQuiz() {
// testQuiz(answers: ["caminas", "anda", "trabajamos", "existís", "ocurren", "recibo", "bebes", "lee", "aprendemos", "vais", "duermen", "hago", "mueres", "muerde", "oímos", "podéis", "han", "siento", "sabrás", "cabrá", "podremos", "querréis", "pondrán", "tendré", "vendrás", "saldrá", "estudiaremos", "escucharéis", "visitarán", "permitiré", "partirás", "comprenderá", "correremos", "fuisteis", "dieron", "puse", "pudiste", "estuvo", "tuvimos", "anduvisteis", "supieron", "caminé", "anduviste", "trabajó", "estudiamos", "escuchastéis", "visitaron", "viajé", "enseñaste", "llevó"], region: "Spain", difficulty: "Easy")
// }
//
// func testEasyLatinAmericaQuiz() {
// testQuiz(answers: ["caminas", "anda", "trabajamos", "existen", "ocurro", "recibes", "bebe", "leemos", "aprenden", "voy", "duermes", "hace", "morimos", "muerden", "oigo", "puedes", "ha", "sentimos", "sabrán", "cabré", "podrás", "querrá", "pondremos", "tendrán", "vendré", "saldrás", "estudiará", "escucharemos", "visitarán", "permitiré", "partirás", "comprenderá", "correremos", "fueron", "di", "pusiste", "pudo", "estuvimos", "tuvieron", "anduve", "supiste", "caminó", "anduvimos", "trabajaron", "estudié", "escuchaste", "visitó", "viajamos", "enseñaron", "llevé"], region: "Latin America", difficulty: "Easy")
// }
//
// func testQuiz(answers: [String], region: String, difficulty: String) {
// let app = XCUIApplication()
// app.launchArguments = [enableUiTesting, region, difficulty]
// app.launch()
// app.tabBars.buttons["Quiz"].tap()
// let timeout: TimeInterval = 1.0
// XCTAssert(app.buttons["Start"].waitForExistence(timeout: timeout))
// app.buttons["Start"].tap()
// let textField = app.textFields[" conjugation"]
// answers.forEach { conjugation in
// textField.typeText(conjugation + "\n")
// }
// XCTAssert(app.staticTexts["Results"].waitForExistence(timeout: timeout))
// XCTAssert(app.staticTexts[region].exists)
// XCTAssert(app.staticTexts[difficulty].exists)
// }
//}
import XCTest

class QuizVCUITests: XCTestCase {
let enableUiTesting = "enable-ui-testing"

override func setUp() {
continueAfterFailure = false
}

override func tearDown() {}

func testDifficultSpainQuiz() {
testQuiz(answers: ["sintiendo", "midiendo", "caminando", "existiendo", "bebiendo", "andas", "ocurre", "leemos", "vais", "duermen", "hago", "fuiste", "dio", "pusimos", "trabajastéis", "recibieron", "aprendí", "ibas", "veía", "caminábamos", "andabais", "sabrán", "cabré", "trabajarás", "estudiará", "escucharíamos", "visitaríais", "podrían", "vaya", "hayas", "sepa", "estudiemos", "permitáis", "comprendan", "pudiera", "viajases", "estuviere", "enseñáremos", "ve", "llevad", "no llegen", "he cubierto", "hubiste bailado", "había dicho", "habremos nadado", "habríais escrito", "hayan cocinado", "hubiera hecho", "hubieses charlado", "hubiere muerto"], region: "Spain", difficulty: "Difficult")
}

func testDifficultLatinAmericaQuiz() {
testQuiz(answers: ["sintiendo", "midiendo", "caminando", "existiendo", "bebiendo", "andas", "ocurre", "leemos", "van", "duermo", "haces", "fue", "dimos", "pusieron", "trabajé", "recibiste", "aprendió", "ibamos", "veían", "caminaba", "andabas", "sabrá", "cabremos", "trabajarán", "estudiaré", "escucharías", "visitaría", "podríamos", "vayan", "haya", "sepas", "estudie", "permitamos", "comprendan", "pudiera", "viajases", "estuviere", "enseñáremos", "ve", "lleven", "no llege", "hemos cubierto", "hubieron bailado", "había dicho", "habrás nadado", "habría escrito", "hayamos cocinado", "hubieran hecho", "hubiese charlado", "hubieres muerto"], region: "Latin America", difficulty: "Difficult")
}

func testModerateSpainQuiz() {
testQuiz(answers: ["caminas", "anda", "existimos", "bebéis", "van", "duermo", "haces", "muere", "sabremos", "cabréis", "podrán", "caminaré", "andarás", "querría", "pondríamos", "tendríais", "trabajarían", "estudiaría", "has cubierto", "ha dicho", "hemos escrito", "habéis escuchado", "han visitado", "iba", "veías", "era", "viajábamos", "enseñabais", "llevaban", "fui", "diste", "puso", "trabajamos", "ocurristeis", "leieron", "vaya", "hayas", "sepa", "llegemos", "bailéis", "sintiendo", "midiendo", "nadando", "cocinando", "ve", "he", "charlen", "platice", "no lloremos", "no esperéis"], region: "Spain", difficulty: "Moderate")
}

func testModerateLatinAmericaQuiz() {
testQuiz(answers: ["caminas", "anda", "existimos", "beben", "voy", "duermes", "hace", "morimos", "sabrán", "cabré", "podrás", "caminará", "andaremos", "querrían", "pondría", "tendrías", "trabajaría", "estudiaríamos", "han cubierto", "he dicho", "has escrito", "ha escuchado", "hemos visitado", "iban", "veía", "eras", "viajaba", "enseñábamos", "llevaban", "fui", "diste", "puso", "trabajamos", "ocurrieron", "leí", "vayas", "haya", "sepamos", "llegen", "baile", "sintiendo", "midiendo", "nadando", "cocinando", "ve", "he", "charle", "platicemos", "no lloren", "no espere"], region: "Latin America", difficulty: "Moderate")
}

func testEasySpainQuiz() {
testQuiz(answers: ["caminas", "anda", "trabajamos", "existís", "ocurren", "recibo", "bebes", "lee", "aprendemos", "vais", "duermen", "hago", "mueres", "muerde", "oímos", "podéis", "han", "siento", "sabrás", "cabrá", "podremos", "querréis", "pondrán", "tendré", "vendrás", "saldrá", "estudiaremos", "escucharéis", "visitarán", "permitiré", "partirás", "comprenderá", "correremos", "fuisteis", "dieron", "puse", "pudiste", "estuvo", "tuvimos", "anduvisteis", "supieron", "caminé", "anduviste", "trabajó", "estudiamos", "escuchastéis", "visitaron", "viajé", "enseñaste", "llevó"], region: "Spain", difficulty: "Easy")
}

func testEasyLatinAmericaQuiz() {
testQuiz(answers: ["caminas", "anda", "trabajamos", "existen", "ocurro", "recibes", "bebe", "leemos", "aprenden", "voy", "duermes", "hace", "morimos", "muerden", "oigo", "puedes", "ha", "sentimos", "sabrán", "cabré", "podrás", "querrá", "pondremos", "tendrán", "vendré", "saldrás", "estudiará", "escucharemos", "visitarán", "permitiré", "partirás", "comprenderá", "correremos", "fueron", "di", "pusiste", "pudo", "estuvimos", "tuvieron", "anduve", "supiste", "caminó", "anduvimos", "trabajaron", "estudié", "escuchaste", "visitó", "viajamos", "enseñaron", "llevé"], region: "Latin America", difficulty: "Easy")
}

func testQuiz(answers: [String], region: String, difficulty: String) {
let app = XCUIApplication()
app.launchArguments = [enableUiTesting, region, difficulty]
app.launch()
app.tabBars.buttons["Quiz"].tap()
let timeout: TimeInterval = 1.0
XCTAssert(app.buttons["Start"].waitForExistence(timeout: timeout))
app.buttons["Start"].tap()
let textField = app.textFields[" conjugation"]
answers.forEach { conjugation in
textField.typeText(conjugation + "\n")
}
XCTAssert(app.staticTexts["Results"].waitForExistence(timeout: timeout))
XCTAssert(app.staticTexts[region].exists)
XCTAssert(app.staticTexts[difficulty].exists)
}
}

0 comments on commit e20b949

Please sign in to comment.