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

Test suite enhancements #44

Merged
merged 5 commits into from Dec 27, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions MetovaTestKit.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
4A2294F421D5180200D093A6 /* TestFailureExpectation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2294F321D5180200D093A6 /* TestFailureExpectation.swift */; };
4A2294F621D531B000D093A6 /* DetailedTestFailureExpectation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A2294F521D531B000D093A6 /* DetailedTestFailureExpectation.swift */; };
4A22950C21D564D500D093A6 /* BasicTestFailureExpectation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A22950B21D564D500D093A6 /* BasicTestFailureExpectation.swift */; };
4A3CFEFB1CDD5F37003EF6F0 /* MetovaTestKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A3CFEFA1CDD5F37003EF6F0 /* MetovaTestKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
4A3CFF021CDD5F37003EF6F0 /* MetovaTestKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A3CFEF71CDD5F37003EF6F0 /* MetovaTestKit.framework */; };
4A3CFFCB1CDE1473003EF6F0 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A3CFFCA1CDE1473003EF6F0 /* XCTest.framework */; };
Expand Down Expand Up @@ -60,6 +63,9 @@

/* Begin PBXFileReference section */
152CC7EA0C83675F6522A85B /* Pods-MetovaTestKit.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MetovaTestKit.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MetovaTestKit/Pods-MetovaTestKit.debug.xcconfig"; sourceTree = "<group>"; };
4A2294F321D5180200D093A6 /* TestFailureExpectation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestFailureExpectation.swift; sourceTree = "<group>"; };
4A2294F521D531B000D093A6 /* DetailedTestFailureExpectation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailedTestFailureExpectation.swift; sourceTree = "<group>"; };
4A22950B21D564D500D093A6 /* BasicTestFailureExpectation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicTestFailureExpectation.swift; sourceTree = "<group>"; };
4A3CFEF71CDD5F37003EF6F0 /* MetovaTestKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MetovaTestKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4A3CFEFA1CDD5F37003EF6F0 /* MetovaTestKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MetovaTestKit.h; sourceTree = "<group>"; };
4A3CFEFC1CDD5F37003EF6F0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -74,7 +80,7 @@
4A3CFFCA1CDE1473003EF6F0 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
4A3CFFCD1CDE1548003EF6F0 /* ExceptionTestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExceptionTestingTests.swift; sourceTree = "<group>"; };
4A771F341D4C173300EFD0B8 /* ConstraintTestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConstraintTestingTests.swift; sourceTree = "<group>"; };
4A771FC81D4D534200EFD0B8 /* MTKBaseTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MTKBaseTestCase.swift; path = "Supporting Test Files/MTKBaseTestCase.swift"; sourceTree = "<group>"; };
4A771FC81D4D534200EFD0B8 /* MTKBaseTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MTKBaseTestCase.swift; sourceTree = "<group>"; };
4A8AD4F31CDEB7A60085984D /* TestableProtocolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestableProtocolTests.swift; sourceTree = "<group>"; };
4A8AD4F51CDEDF110085984D /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = "<group>"; };
4A8AD4F71CDEE4220085984D /* .travis.yml */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = text; path = .travis.yml; sourceTree = "<group>"; };
Expand Down Expand Up @@ -167,6 +173,17 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
4A2294F221D517AD00D093A6 /* TestingUtilities */ = {
isa = PBXGroup;
children = (
4A771FC81D4D534200EFD0B8 /* MTKBaseTestCase.swift */,
4A2294F321D5180200D093A6 /* TestFailureExpectation.swift */,
4A22950B21D564D500D093A6 /* BasicTestFailureExpectation.swift */,
4A2294F521D531B000D093A6 /* DetailedTestFailureExpectation.swift */,
);
path = TestingUtilities;
sourceTree = "<group>";
};
4A3CFEED1CDD5F37003EF6F0 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -207,6 +224,7 @@
4A3CFF051CDD5F37003EF6F0 /* MetovaTestKitTests */ = {
isa = PBXGroup;
children = (
4A2294F221D517AD00D093A6 /* TestingUtilities */,
6EC1A6B11EBCE2C7000DEFA6 /* AsynchronousTestingTests */,
4AEFB76521D403B7007FA095 /* DateTestingTests */,
4ADA98FF214AAA7900B91CF2 /* ExceptionTestingTests */,
Expand Down Expand Up @@ -282,7 +300,6 @@
4A8AD4EE1CDEB6300085984D /* Supporting Test Files */ = {
isa = PBXGroup;
children = (
4A771FC81D4D534200EFD0B8 /* MTKBaseTestCase.swift */,
4A3CFF081CDD5F37003EF6F0 /* Info.plist */,
);
name = "Supporting Test Files";
Expand Down Expand Up @@ -715,7 +732,10 @@
files = (
4A771F351D4C173300EFD0B8 /* ConstraintTestingTests.swift in Sources */,
4A771FC91D4D534200EFD0B8 /* MTKBaseTestCase.swift in Sources */,
4A22950C21D564D500D093A6 /* BasicTestFailureExpectation.swift in Sources */,
4A8AD4F41CDEB7A60085984D /* TestableProtocolTests.swift in Sources */,
4A2294F421D5180200D093A6 /* TestFailureExpectation.swift in Sources */,
4A2294F621D531B000D093A6 /* DetailedTestFailureExpectation.swift in Sources */,
6E0D0B461F1FEE3900600571 /* UIBarButtonItemTestingTests.swift in Sources */,
4ADA98FC214AAA2D00B91CF2 /* UIAlertControllerTestingTests.swift in Sources */,
4ADA98F1214AAA0700B91CF2 /* TestableViewController.swift in Sources */,
Expand Down
Expand Up @@ -88,7 +88,7 @@ class AsyncTestingTests: MTKBaseTestCase {

func testAsyncTestFailsWhenAssertionFailsInTheTestActionClosure() {

let expectedFailure = TestFailureExpectation(description: "Description", filePath: "File", lineNumber: 1)
let expectedFailure = BasicTestFailureExpectation(description: "Description", filePath: "File", lineNumber: 1)

expectTestFailure(expectedFailure) {

Expand Down
15 changes: 11 additions & 4 deletions MetovaTestKitTests/DateTestingTests/MTKDateTestingTests.swift
Expand Up @@ -74,20 +74,27 @@ class DateTestingTests: MTKBaseTestCase {
components.hour = 6
components.minute = 57
components.second = 42
components.nanosecond = 8675309
guard let date1 = Calendar.current.date(from: components) else {
XCTFail("Failed to instantiate test date 1!")
return
}

components.second = 43
components.nanosecond = 0
guard let date2 = Calendar.current.date(from: components) else {
XCTFail("Failed to instantiate test date 2!")
return
}

let description = "failed - \n second value (42) of lhs is not equal to second value (43) of rhs"
expectTestFailure(TestFailureExpectation(description: description, lineNumber: #line+1)) {
MTKAssertEqualDates(date1, date2, comparing: .year, .month, .day, .hour, .minute, .second)
let descriptionParts = [
"failed -",
"second value (42) of lhs is not equal to second value (43) of rhs",
"nanosecond value (8675336) of lhs is not equal to nanosecond value (0) of rhs"
]

expectTestFailure(DetailedTestFailureExpectation(descriptionSubstrings: descriptionParts, lineNumber: #line+1)) {
MTKAssertEqualDates(date1, date2, comparing: .year, .month, .day, .hour, .minute, .second, .nanosecond)
}
}

Expand All @@ -111,7 +118,7 @@ class DateTestingTests: MTKBaseTestCase {
}

let description = "failed - MTKAssertEqualDates failure - Custom Message!"
expectTestFailure(TestFailureExpectation(description: description, lineNumber: #line+1)) {
expectTestFailure(BasicTestFailureExpectation(description: description, lineNumber: #line+1)) {
MTKAssertEqualDates(date1, date2, comparing: .year, .month, .day, .hour, .minute, .second, .nanosecond, message: "Custom Message!")
}
}
Expand Down
Expand Up @@ -82,8 +82,7 @@ class ExceptionTestingTests: MTKBaseTestCase {

var didReachEnd: Bool?

expectTestFailure(TestFailureExpectation(description: description, lineNumber: 87)) {

expectTestFailure(BasicTestFailureExpectation(description: description, lineNumber: #line+1)) {
MTKAssertNoException(message: message) {
didReachEnd = false

Expand All @@ -109,8 +108,7 @@ class ExceptionTestingTests: MTKBaseTestCase {

var didReachEnd: Bool?

expectTestFailure(TestFailureExpectation(description: description, lineNumber: 114)) {

expectTestFailure(BasicTestFailureExpectation(description: description, lineNumber: #line+1)) {
MTKAssertNoException {
didReachEnd = false

Expand Down Expand Up @@ -188,10 +186,8 @@ class ExceptionTestingTests: MTKBaseTestCase {

var didReachEnd: Bool?

expectTestFailure(TestFailureExpectation(description: description, lineNumber: 193)) {

expectTestFailure(BasicTestFailureExpectation(description: description, lineNumber: #line+1)) {
MTKAssertException(message: message) {

didReachEnd = false

let array: NSArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Expand All @@ -216,10 +212,8 @@ class ExceptionTestingTests: MTKBaseTestCase {

var didReachEnd: Bool?

expectTestFailure(TestFailureExpectation(description: description, lineNumber: 221)) {

expectTestFailure(BasicTestFailureExpectation(description: description, lineNumber: #line+1)) {
MTKAssertException {

didReachEnd = false

let array: NSArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Expand Down
Expand Up @@ -43,7 +43,7 @@ class FailureRecordingTests: MTKBaseTestCase {
func testRecordingFailureWithMessageAndDescription() {

let line: UInt = 100
let testFailureExpectation = TestFailureExpectation(description: "failed - Description - Message", filePath: #file, lineNumber: line)
let testFailureExpectation = BasicTestFailureExpectation(description: "failed - Description - Message", filePath: #file, lineNumber: line)

expectTestFailure(testFailureExpectation) {
MTKRecordFailure(withMessage: "Message", description: "Description", file: #file, line: line)
Expand Down
@@ -0,0 +1,71 @@
//
// BasicTestFailureExpectation.swift
// MetovaTestKit
//
// Created by Nick Griffith on 2018-12-27.
// Copyright © 2018 Metova. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

struct BasicTestFailureExpectation: TestFailureExpectation {

let description: String?
let filePath: String?
let lineNumber: UInt?

init(description: String? = nil, filePath: String? = nil, lineNumber: UInt? = nil) {
self.description = description
self.filePath = filePath
self.lineNumber = lineNumber
}

func verifyDescription(_ description: String) -> TestVerificationResult {
guard let expectedDescription = self.description else { return .expected }

guard description == expectedDescription else {
return .mismatch("Description mismatch - Expected: `\(expectedDescription)` Actual: `\(description)`")
}

return .expected
}

func verifyFilePath(_ filePath: String) -> TestVerificationResult {
guard let expectedFilePath = self.filePath else { return .expected }

guard filePath == expectedFilePath else {
return .mismatch("File Path mismatch - Expected: `\(expectedFilePath)` Actual: `\(filePath)`")
}

return .expected
}

func verifyLineNumber(_ lineNumber: Int) -> TestVerificationResult {
guard let expectedLineNumber = self.lineNumber else { return .expected }

guard lineNumber == expectedLineNumber else {
return .mismatch("Line Number mismatch - Expected: `\(expectedLineNumber)` Actual: `\(lineNumber)`")
}

return .expected
}
}
@@ -0,0 +1,73 @@
//
// DetailedTestFailureExpectation.swift
// MetovaTestKit
//
// Created by Nick Griffith on 2018-12-27.
// Copyright © 2018 Metova. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

struct DetailedTestFailureExpectation: TestFailureExpectation {

let descriptionSubstrings: [String]?
let filePath: String?
let lineNumber: UInt?

init(descriptionSubstrings: [String]? = nil, filePath: String? = nil, lineNumber: UInt? = nil) {
self.descriptionSubstrings = descriptionSubstrings
self.filePath = filePath
self.lineNumber = lineNumber
}

func verifyDescription(_ description: String) -> TestVerificationResult {
guard let expectedSubstrings = descriptionSubstrings else { return .expected }

let missingSubstrings = expectedSubstrings.filter { !description.contains($0) }

guard missingSubstrings.isEmpty else {
return .mismatch("Description mismatch\nActual:***\n\(description)`\n***\nmissing substrings:\n\t\(missingSubstrings.joined(separator: "\n\t"))")
}

return .expected
}

func verifyFilePath(_ filePath: String) -> TestVerificationResult {
guard let expectedFilePath = self.filePath else { return .expected }

guard filePath == expectedFilePath else {
return .mismatch("File Path mismatch - Expected: `\(expectedFilePath)` Actual: `\(filePath)`")
}

return .expected
}

func verifyLineNumber(_ lineNumber: Int) -> TestVerificationResult {
guard let expectedLineNumber = self.lineNumber else { return .expected }

guard lineNumber == expectedLineNumber else {
return .mismatch("Line Number mismatch - Expected: `\(expectedLineNumber)` Actual: `\(lineNumber)`")
}

return .expected
}
BevTheDev marked this conversation as resolved.
Show resolved Hide resolved
}