Question

I am trying to change the existent defaultTestSuite method to create a class that can pick test methods from different classes and execute them in a specific order. However every time I import a test file in another test file i get a linker error

duplicate symbol _OBJC_METACLASS_$_TMKTestExample

Why does this happen with OCUnit, how could I fix this?

Regards

Was it helpful?

Solution 2

I found the solution by creating my own NSInvocations in the testInvocation method that belongs to the SenTestCase.

Basically i have an empty test Class which i throw test methods that execute some action (for flow testing), which are setup in each NSInvocation, once the test runs, the methods will be executed in the same order as the exist in the testInvocation static method, and it Permits to add as many methods as possible, in something similar to the crude example below:

Extend the SenTestCase class

- (id) initWithInvocation:(NSInvocation *)anInvocation
{
    id invocationTarget = anInvocation.target;
    self = [super initWithInvocation:anInvocation];

    if (!self) {
        return nil;
    }

    if (invocationTarget != nil && invocationTarget != self) {
        anInvocation.target = invocationTarget;
    }

    return self;

}

It is necessary to override the method above because the target will always be set to self in the super initWithInvocation method.

+(NSArray *) testInvocations
{


    NSMutableArray *invocations = (NSMutableArray *)[super testInvocations];
    TMKTestFirstViewControllerBaseAction *baseAction = [TMKTestFirstViewControllerBaseAction sharedInstance];
    for (int i=0; i<4; i++) {
        NSInvocation *invocation = nil;

        switch (i) {
            case 3:{
                invocation = [NSInvocation invocationWithTarget:baseAction      selector:@selector(tapChangeBackgroundButton)];
                break;
            }
            case 2:{
                invocation = [NSInvocation invocationWithTarget:baseAction selector:@selector(tapChangeBackgroundButton)];
                break;
            }
            case 0:{
                invocation = [NSInvocation invocationWithTarget:baseAction selector:@selector(tapBarButtonWithAccessibilityLabel:)];
                NSString *arg = @"Second";
            [invocation setArgument:&arg atIndex:2];
                break;
            }
            case 1:{
            invocation = [NSInvocation invocationWithTarget:baseAction  selector:@selector(tapBarButtonWithAccessibilityLabel:)];
                NSString *arg = @"First";
                [invocation setArgument:&arg atIndex:2];
                break;
            }
            default:
                break;
        }
        [invocation retainArguments];
        NSLog(@"invocation target: %d target: %@", i,invocation.target);
         [invocations insertObject:invocation atIndex:i+1];


    }

    return invocations;
}

The example above only adds one test but it is possible to see what I mean, this was taken from examples in these websites:

Using both of these and manipulating the order of tests, i am able to create the following for KIF: - Classes that describe actions to test in a specific UIViewController/UIView/etc., and then reuse the methods to create flow tests, regression UI tests, from code or from scripts (still doing the latter). - normal test classes.

I hope this helps whoever needs this very specific requirement.

Regarding the original question i haven't figured it out, i wonder if there is a way.

OTHER TIPS

Check your TMKTestExample's Target Membership, it should not be included in both the main target and the unit test target.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top