SwiftTesting parameterized tests

Overview

  • Using parameterized tests in Swift Testing causes a crash
  • Sometimes I feel it could be valid to pass duplicate values in as the parameter as shown in the code below.

Question:

  • Is there a better way (workaround) to test this code in SwiftTesting?

Note: I understand this is a known issue but is there a workaround?

Runtime Error / Crash:

Thread 3: Fatal error: Internal inconsistency: No test reporter for test case argumentIDs: nil in test DemoTests.DemoTests/sky(_:expectation:)/DemoTests.swift:27:6

Possible cause:

Duplication of parameter values, but in this case it is a valid scenario to repeat values

Environment:

  • Xcode 16.3 (16E140)

Code

enum Sky {
    case sun
    case moon
    
    init(value1: Int) {
        let isEven = value1 % 2 == 0
        if isEven {
            self = .sun
        } else {
            self = .moon
        }
    }
}

struct DemoTests {
    
    @Test(arguments: zip(
        [Sky(value1: 3), Sky(value1: 1)],
        [Sky.moon, .moon])
    )
    func sky(_ status: Sky, expectation: Sky) {
        #expect(status == expectation)
    }
}

You could just use the integer values as arguments and move the initialiser into the test function?

struct DemoTests {
    @Test(arguments: zip(
        [3, 1],
        [Sky.moon, .moon])
    )
    func sky(_ value: Int, expectation: Sky) {
        #expect(Sky(value1: value) == expectation)
    }
}
1 Like

Perfect!!! thanks a lot!!

1 Like