From 7cb03253ca991a417510126dde75d864343f97bd Mon Sep 17 00:00:00 2001 From: Benji Encz Date: Mon, 22 Jan 2018 11:19:29 -0800 Subject: [PATCH] [Tests] Fix Existing Tests Gets the existing tests working as is. Follow-up commits will refactor the tests. --- ReactiveLists.xcodeproj/project.pbxproj | 10 +++----- .../xcschemes/ReactiveLists.xcscheme | 3 ++- Tests/FluxCollectionViewDataSourceTests.swift | 1 - Tests/FluxCollectionViewModelTests.swift | 1 - Tests/FluxTableViewDataSourceTests.swift | 1 - Tests/XCTest+Parameterized.swift | 25 +++++++++++++++++++ 6 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 Tests/XCTest+Parameterized.swift diff --git a/ReactiveLists.xcodeproj/project.pbxproj b/ReactiveLists.xcodeproj/project.pbxproj index 1815aab..a21914f 100644 --- a/ReactiveLists.xcodeproj/project.pbxproj +++ b/ReactiveLists.xcodeproj/project.pbxproj @@ -8,8 +8,7 @@ /* Begin PBXBuildFile section */ 0ABAC2EBC76C5C0A6354C8F6 /* Pods_ReactiveLists_ReactiveListsExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F35530D29268B112F99A187 /* Pods_ReactiveLists_ReactiveListsExample.framework */; }; - 2540F4A21F0DA46B003B4C66 /* PlanLib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2540F4A01F0DA395003B4C66 /* PlanLib.framework */; }; - 2540F4A91F0DB018003B4C66 /* PlanLib.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 2540F4A01F0DA395003B4C66 /* PlanLib.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 2537A64B201672B80044469D /* XCTest+Parameterized.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2537A649201671F20044469D /* XCTest+Parameterized.swift */; }; 2541B7321F298A69002C3090 /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2541B7311F298A69002C3090 /* Models.swift */; }; 2541B73D1F29A13B002C3090 /* Diffing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2541B73C1F29A13B002C3090 /* Diffing.swift */; }; 2576640E1F29075C00C037E3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2576640D1F29075C00C037E3 /* AppDelegate.swift */; }; @@ -36,7 +35,6 @@ 258E31E81F0D90BC00D6F324 /* SharedFluxTableViewDataSourceMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 258E31E01F0D90BC00D6F324 /* SharedFluxTableViewDataSourceMocks.swift */; }; 258E31E91F0D90BC00D6F324 /* TestFluxCollectionViewModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 258E31E11F0D90BC00D6F324 /* TestFluxCollectionViewModels.swift */; }; 258E31EA1F0D90BC00D6F324 /* TestFluxTableViewModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 258E31E21F0D90BC00D6F324 /* TestFluxTableViewModels.swift */; }; - 258E31EE1F0D9A3600D6F324 /* PGSharedTestUtils.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 258E31ED1F0D9A3600D6F324 /* PGSharedTestUtils.framework */; }; 25D0D4321F2952EA00596AED /* FluxTableViewDiffingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25D0D4311F2952EA00596AED /* FluxTableViewDiffingTests.swift */; }; 7C24B1408A8B3A147C254BCA /* Pods_ReactiveLists.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 978763204EC113AFD1F7EB54 /* Pods_ReactiveLists.framework */; }; BB2B5FDE1BFA1903A6750AD3 /* Pods_ReactiveListsTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932473A2DAECE0F923C4B570 /* Pods_ReactiveListsTests.framework */; }; @@ -66,13 +64,13 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 2540F4A91F0DB018003B4C66 /* PlanLib.framework in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 2537A649201671F20044469D /* XCTest+Parameterized.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "XCTest+Parameterized.swift"; sourceTree = ""; }; 2540F4A01F0DA395003B4C66 /* PlanLib.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PlanLib.framework; path = "../Debug-iphonesimulator/PlanLib.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; 2541B7311F298A69002C3090 /* Models.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Models.swift; sourceTree = ""; }; 2541B73C1F29A13B002C3090 /* Diffing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Diffing.swift; sourceTree = ""; }; @@ -141,8 +139,6 @@ buildActionMask = 2147483647; files = ( 258E31991F0D8CBC00D6F324 /* ReactiveLists.framework in Frameworks */, - 2540F4A21F0DA46B003B4C66 /* PlanLib.framework in Frameworks */, - 258E31EE1F0D9A3600D6F324 /* PGSharedTestUtils.framework in Frameworks */, BB2B5FDE1BFA1903A6750AD3 /* Pods_ReactiveListsTests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -222,6 +218,7 @@ 258E319C1F0D8CBC00D6F324 /* Tests */ = { isa = PBXGroup; children = ( + 2537A649201671F20044469D /* XCTest+Parameterized.swift */, 258E31DB1F0D90BC00D6F324 /* FluxCollectionViewDataSourceTests.swift */, 258E31DC1F0D90BC00D6F324 /* FluxCollectionViewModelTests.swift */, 258E31DE1F0D90BC00D6F324 /* FluxTableViewDataSourceTests.swift */, @@ -585,6 +582,7 @@ 258E31E81F0D90BC00D6F324 /* SharedFluxTableViewDataSourceMocks.swift in Sources */, 25D0D4321F2952EA00596AED /* FluxTableViewDiffingTests.swift in Sources */, 258E31E91F0D90BC00D6F324 /* TestFluxCollectionViewModels.swift in Sources */, + 2537A64B201672B80044469D /* XCTest+Parameterized.swift in Sources */, 258E31E71F0D90BC00D6F324 /* FluxTableViewModelTests.swift in Sources */, 258E31E61F0D90BC00D6F324 /* FluxTableViewDataSourceTests.swift in Sources */, 258E31EA1F0D90BC00D6F324 /* TestFluxTableViewModels.swift in Sources */, diff --git a/ReactiveLists.xcodeproj/xcshareddata/xcschemes/ReactiveLists.xcscheme b/ReactiveLists.xcodeproj/xcshareddata/xcschemes/ReactiveLists.xcscheme index eee1f74..90d8297 100644 --- a/ReactiveLists.xcodeproj/xcshareddata/xcschemes/ReactiveLists.xcscheme +++ b/ReactiveLists.xcodeproj/xcshareddata/xcschemes/ReactiveLists.xcscheme @@ -27,7 +27,8 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" language = "" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> diff --git a/Tests/FluxCollectionViewDataSourceTests.swift b/Tests/FluxCollectionViewDataSourceTests.swift index c143ce7..65f49f9 100644 --- a/Tests/FluxCollectionViewDataSourceTests.swift +++ b/Tests/FluxCollectionViewDataSourceTests.swift @@ -7,7 +7,6 @@ // import Nimble -import PGSharedTestUtils @testable import ReactiveLists import ReactiveSwift import UIKit diff --git a/Tests/FluxCollectionViewModelTests.swift b/Tests/FluxCollectionViewModelTests.swift index 422ca6e..3dcbd6b 100644 --- a/Tests/FluxCollectionViewModelTests.swift +++ b/Tests/FluxCollectionViewModelTests.swift @@ -6,7 +6,6 @@ // Copyright © 2016 PlanGrid. All rights reserved. // -import PGSharedTestUtils @testable import ReactiveLists import ReactiveSwift import XCTest diff --git a/Tests/FluxTableViewDataSourceTests.swift b/Tests/FluxTableViewDataSourceTests.swift index 7407a4e..9525c75 100644 --- a/Tests/FluxTableViewDataSourceTests.swift +++ b/Tests/FluxTableViewDataSourceTests.swift @@ -7,7 +7,6 @@ // import Nimble -import PGSharedTestUtils @testable import ReactiveLists import ReactiveSwift import XCTest diff --git a/Tests/XCTest+Parameterized.swift b/Tests/XCTest+Parameterized.swift new file mode 100644 index 0000000..25d64ec --- /dev/null +++ b/Tests/XCTest+Parameterized.swift @@ -0,0 +1,25 @@ +/** + Allows to perform a parameterized tests, in which each test case can have different inputs and + expecations but in which the test preparation & execution code are shared. + */ +public struct ParameterizedTest { + + public typealias Expectation = (TestParameter) -> Void + public typealias TestCase = (TestParameter, expectation: Expectation) + public typealias TestClosure = (TestParameter, Expectation) -> Void + + public static func test(testCases: [TestCase], testClosure: TestClosure) { + testCases.forEach { testClosure($0.0, $0.expectation) } + } +} + +/// Run the same expectation code for any number of single parameter cases +/// +/// Note: For type inferencing to work on nil cases, you may have to do two things: +/// +/// (1) order the nil case first in the list of cases +/// +/// (2) explicitly type the nil, e.g. `Optional()` +public func parameterize(cases: A..., expectation: ((A) -> Void)) { + cases.forEach { expectation($0) } +}