Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 593
Gavin Hope Avatar asked Sep 13 '25 13:09

Gavin Hope


1 Answers

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.

like image 50
Mike D Avatar answered Sep 16 '25 04:09

Mike D