From c102bac8910fd66aef9afb637b31a3a5879d87a6 Mon Sep 17 00:00:00 2001 From: Cameron Cooke Date: Mon, 5 Dec 2022 18:45:19 +0000 Subject: [PATCH] Add ability to override test names --- .../ParameterizedTestsCase1.swift | 6 +++++- .../ParameterizedTestsCase2.swift | 9 ++++++++- .../ParameterizedTestsCase3.swift | 10 +++++++++- .../ParameterizedTestsCase4.swift | 11 ++++++++++- .../ParameterizedTestsCase5.swift | 12 +++++++++++- .../ParameterizedTestsCase6.swift | 13 ++++++++++++- .../ParameterizedTestsCase7.swift | 14 +++++++++++++- .../ParameterizedTestsCase8.swift | 16 ++++++++++++++-- .../ParameterizedTestsCase9.swift | 17 +++++++++++++++-- 9 files changed, 97 insertions(+), 11 deletions(-) diff --git a/Sources/ParameterizedTesting/ParameterizedTestsCase1.swift b/Sources/ParameterizedTesting/ParameterizedTestsCase1.swift index 54fe6e6..cb77eb2 100644 --- a/Sources/ParameterizedTesting/ParameterizedTestsCase1.swift +++ b/Sources/ParameterizedTesting/ParameterizedTestsCase1.swift @@ -21,7 +21,7 @@ open class ParameterizedTestCase1: XCTestCase { { value1 in let selector = ParameterizedTestCase1.registerTestMethod( - name: "\(value1)".lowercased(), + name: testName(value1), testMethod: #selector(self.internalHandler) ) @@ -56,6 +56,10 @@ open class ParameterizedTestCase1: XCTestCase { nil } + open class func testName(_ value1: IN1) -> String { + "\(value1)".lowercased() + } + open func testAllCombinations(_ value1: IN1, _ expectedResult: OUT?) { fatalError("Not implemented") } diff --git a/Sources/ParameterizedTesting/ParameterizedTestsCase2.swift b/Sources/ParameterizedTesting/ParameterizedTestsCase2.swift index bbb0817..ce0d604 100644 --- a/Sources/ParameterizedTesting/ParameterizedTestsCase2.swift +++ b/Sources/ParameterizedTesting/ParameterizedTestsCase2.swift @@ -22,7 +22,7 @@ open class ParameterizedTestCase2: XCTestCase { { value1, value2 in let selector = ParameterizedTestCase2.registerTestMethod( - name: "\(value1)_\(value2)".lowercased(), + name: testName(value1, value2), testMethod: #selector(self.internalHandler) ) @@ -58,6 +58,13 @@ open class ParameterizedTestCase2: XCTestCase { nil } + open class func testName( + _ value1: IN1, + _ value2: IN2 + ) -> String { + "\(value1)_\(value2)".lowercased() + } + open func testAllCombinations(_ value1: IN1, _ value2: IN2, _ expectedResult: OUT?) { fatalError("Not implemented") } diff --git a/Sources/ParameterizedTesting/ParameterizedTestsCase3.swift b/Sources/ParameterizedTesting/ParameterizedTestsCase3.swift index 511c92b..ad6ecfd 100644 --- a/Sources/ParameterizedTesting/ParameterizedTestsCase3.swift +++ b/Sources/ParameterizedTesting/ParameterizedTestsCase3.swift @@ -23,7 +23,7 @@ open class ParameterizedTestCase3: XCTestCase { { value1, value2, value3 in let selector = ParameterizedTestCase3.registerTestMethod( - name: "\(value1)_\(value2)_\(value3)".lowercased(), + name: testName(value1, value2, value3), testMethod: #selector(self.internalHandler) ) @@ -60,6 +60,14 @@ open class ParameterizedTestCase3: XCTestCase { nil } + open class func testName( + _ value1: IN1, + _ value2: IN2, + _ value3: IN3 + ) -> String { + "\(value1)_\(value2)_\(value3)".lowercased() + } + open func testAllCombinations(_ value1: IN1, _ value2: IN2, _ value3: IN3, _ expectedResult: OUT?) { fatalError("Not implemented") } diff --git a/Sources/ParameterizedTesting/ParameterizedTestsCase4.swift b/Sources/ParameterizedTesting/ParameterizedTestsCase4.swift index 4cd078c..cea7930 100644 --- a/Sources/ParameterizedTesting/ParameterizedTestsCase4.swift +++ b/Sources/ParameterizedTesting/ParameterizedTestsCase4.swift @@ -24,7 +24,7 @@ open class ParameterizedTestCase4: XCTestCase { { value1, value2, value3, value4 in let selector = ParameterizedTestCase4.registerTestMethod( - name: "\(value1)_\(value2)_\(value3)_\(value4)".lowercased(), + name: testName(value1, value2, value3, value4), testMethod: #selector(self.internalHandler) ) @@ -62,6 +62,15 @@ open class ParameterizedTestCase4: XCTestCase { nil } + open class func testName( + _ value1: IN1, + _ value2: IN2, + _ value3: IN3, + _ value4: IN4 + ) -> String { + "\(value1)_\(value2)_\(value3)_\(value4)".lowercased() + } + open func testAllCombinations( _ value1: IN1, _ value2: IN2, diff --git a/Sources/ParameterizedTesting/ParameterizedTestsCase5.swift b/Sources/ParameterizedTesting/ParameterizedTestsCase5.swift index 6e75977..6357407 100644 --- a/Sources/ParameterizedTesting/ParameterizedTestsCase5.swift +++ b/Sources/ParameterizedTesting/ParameterizedTestsCase5.swift @@ -25,7 +25,7 @@ open class ParameterizedTestCase5: XCTestCase { { value1, value2, value3, value4, value5 in let selector = ParameterizedTestCase5.registerTestMethod( - name: "\(value1)_\(value2)_\(value3)_\(value4)_\(value5)".lowercased(), + name: testName(value1, value2, value3, value4, value5), testMethod: #selector(self.internalHandler) ) @@ -64,6 +64,16 @@ open class ParameterizedTestCase5: XCTestCase { nil } + open class func testName( + _ value1: IN1, + _ value2: IN2, + _ value3: IN3, + _ value4: IN4, + _ value5: IN5 + ) -> String { + "\(value1)_\(value2)_\(value3)_\(value4)_\(value5)".lowercased() + } + open func testAllCombinations( _ value1: IN1, _ value2: IN2, diff --git a/Sources/ParameterizedTesting/ParameterizedTestsCase6.swift b/Sources/ParameterizedTesting/ParameterizedTestsCase6.swift index 72f1e73..98028fe 100644 --- a/Sources/ParameterizedTesting/ParameterizedTestsCase6.swift +++ b/Sources/ParameterizedTesting/ParameterizedTestsCase6.swift @@ -27,7 +27,7 @@ open class ParameterizedTestCase6: XCTestCase { value1, value2, value3, value4, value5, value6 in let selector = ParameterizedTestCase6.registerTestMethod( - name: "\(value1)_\(value2)_\(value3)_\(value4)_\(value5)_\(value6)".lowercased(), + name: testName(value1, value2, value3, value4, value5, value6), testMethod: #selector(self.internalHandler) ) @@ -67,6 +67,17 @@ open class ParameterizedTestCase6: XCTestCase nil } + open class func testName( + _ value1: IN1, + _ value2: IN2, + _ value3: IN3, + _ value4: IN4, + _ value5: IN5, + _ value6: IN6 + ) -> String { + "\(value1)_\(value2)_\(value3)_\(value4)_\(value5)_\(value6)".lowercased() + } + open func testAllCombinations( _ value1: IN1, _ value2: IN2, diff --git a/Sources/ParameterizedTesting/ParameterizedTestsCase7.swift b/Sources/ParameterizedTesting/ParameterizedTestsCase7.swift index 4e8240f..e5b9a62 100644 --- a/Sources/ParameterizedTesting/ParameterizedTestsCase7.swift +++ b/Sources/ParameterizedTesting/ParameterizedTestsCase7.swift @@ -28,7 +28,7 @@ open class ParameterizedTestCase7: XCTes { value1, value2, value3, value4, value5, value6, value7 in let selector = ParameterizedTestCase7.registerTestMethod( - name: "\(value1)_\(value2)_\(value3)_\(value4)_\(value5)_\(value6)_\(value7)".lowercased(), + name: testName(value1, value2, value3, value4, value5, value6, value7), testMethod: #selector(self.internalHandler) ) @@ -69,6 +69,18 @@ open class ParameterizedTestCase7: XCTes nil } + open class func testName( + _ value1: IN1, + _ value2: IN2, + _ value3: IN3, + _ value4: IN4, + _ value5: IN5, + _ value6: IN6, + _ value7: IN7 + ) -> String { + "\(value1)_\(value2)_\(value3)_\(value4)_\(value5)_\(value6)_\(value7)".lowercased() + } + open func testAllCombinations( _ value1: IN1, _ value2: IN2, diff --git a/Sources/ParameterizedTesting/ParameterizedTestsCase8.swift b/Sources/ParameterizedTesting/ParameterizedTestsCase8.swift index cec0f44..bf7a2e0 100644 --- a/Sources/ParameterizedTesting/ParameterizedTestsCase8.swift +++ b/Sources/ParameterizedTesting/ParameterizedTestsCase8.swift @@ -29,8 +29,7 @@ open class ParameterizedTestCase8: { value1, value2, value3, value4, value5, value6, value7, value8 in let selector = ParameterizedTestCase8.registerTestMethod( - name: "\(value1)_\(value2)_\(value3)_\(value4)_\(value5)_\(value6)_\(value7)_\(value8)" - .lowercased(), + name: testName(value1, value2, value3, value4, value5, value6, value7, value8), testMethod: #selector(self.internalHandler) ) @@ -72,6 +71,19 @@ open class ParameterizedTestCase8: nil } + open class func testName( + _ value1: IN1, + _ value2: IN2, + _ value3: IN3, + _ value4: IN4, + _ value5: IN5, + _ value6: IN6, + _ value7: IN7, + _ value8: IN8 + ) -> String { + "\(value1)_\(value2)_\(value3)_\(value4)_\(value5)_\(value6)_\(value7)_\(value8)".lowercased() + } + open func testAllCombinations( _ value1: IN1, _ value2: IN2, diff --git a/Sources/ParameterizedTesting/ParameterizedTestsCase9.swift b/Sources/ParameterizedTesting/ParameterizedTestsCase9.swift index d18b5e2..110698a 100644 --- a/Sources/ParameterizedTesting/ParameterizedTestsCase9.swift +++ b/Sources/ParameterizedTesting/ParameterizedTestsCase9.swift @@ -30,8 +30,7 @@ open class ParameterizedTestCase9 String { + "\(value1)_\(value2)_\(value3)_\(value4)_\(value5)_\(value6)_\(value7)_\(value8)_\(value9)".lowercased() + } + open func testAllCombinations( _ value1: IN1, _ value2: IN2,