0

I have several versions (IOS, JavaScript, Android) of the same calculator that have to produce the same result on every platform.

I have developed a set of test data, spread across multiple data sets like:

onedigit.json:
  {n1: 1, n2: 2, a: 3},
  {n1: 4, n2: 5, a: 9}...

twodigit.json
  {n1: 32, n2: 11, a: 43},
  {n1: 42, n2: 0, a: 42}

...and so on.

I have a simple XCTestCase like:

@interface CalculatorAddTest: XCTestCase

@property NSNumber n1;
@property NSNumber n2;
@property NSNumber a;

@end

@implementation CalculatorAddTest

- (void) setUp{
    self.n1 = passedInData.n1;
    self.n2 = passedInData.n2;
    self.a = passedInData.a;
}

- testAdd{
   XCAssert( Calculator.add(self.n1, self.n2) == self.a );
}

- (void) tearDown{
    ...
}

So, the question is, how to I:

for dataSet in dataSets:
    for d in dataSet:
        run CalculatorAddTest with d

i.e. how do I pass my data into passedInData in CalculatorAddTest?

I tried overriding init:, but that didn't even get called (no idea what designated initializer for XCTestCase is and header gives no clues).

Thanks!

ssteinerX

ssteinerX
  • 191
  • 1
  • 6
  • I'm not asking how to do the iteration, just how to get my data into setUp so it can be used as the source data for each of the tests in the test case. – ssteinerX Apr 02 '16 at 15:15

1 Answers1

0

A testable entity that runs multiple XCTestCases is an XCTestSuite. My suggestion would be to try and write a custom XCTestSuite to iterate over your data and create multiple test cases within the suite.

Scott Thompson
  • 22,629
  • 4
  • 32
  • 34
  • Thanks, I found that, what I don't seem to be able to find is how to get the test data, iterated over in the XCTestSuite, sent into the XCTestCase. I want to say "Run this XCTestCase using this test data." instead of having the setUp() just 'know' what data to use. – ssteinerX Apr 02 '16 at 17:22
  • I'm currently looking at this: https://github.com/michalkonturek/XCParameterizedTestCase – ssteinerX Apr 02 '16 at 17:24
  • @ssteinerx An XCTestCase has a very simple interface. All you can do is tell the test case to run, you can't say "run with this data". You are going to have to make the data intrinsic to the XCTestCase at some level, either by constructing the XCTestCase specifically for that data, or by telling the XCTestCase what data it should run against before it is run. – Scott Thompson Apr 02 '16 at 17:25
  • That's what I'm not seeing: "telling the XCTestCase what data it should run against before it is run" It does setUp(), runs the tests, then tearDown(). I don't see any place to get in there to tell it what data to use except maybe through some (gross) global variable or something. – ssteinerX Apr 02 '16 at 18:12