iosxcodeunit-testingxctest

Is it possible to use parameterised test case data with Xcode's XCTest Framework?


Something similar to the TestCaseAttribute that NUnit has, along the lines of:

[TestCase(12,3,4)]
[TestCase(12,2,6)]
[TestCase(12,4,3)]
public void DivideTest(int n, int d, int q)
{
  Assert.AreEqual( q, n / d );
}

Is it possible to provide parameterised test case data like this, in Xcode?


Solution

  • It does not look like XCTest has this built in, but there is project on GitHub aims to add this functionaltiy.

    From their ReadMe:

    KNMParametrizedTest adds support for parametrized test cases using the XCTest framework. Here is an example:

    KNMParametersFor(testExample, @[ @"Hello", @"World" ]) - (void)testExample:(NSString *)word { NSString *result = [myUppercaser uppercaseString:word]; XCTAssertEqualObjects(result, [word uppercaseString], @"Uppercaser failed for word %@", word); }

    It looks like the easiest way to install this is through CocoaPods.