Get access to the classes in another target with KIF

165 Views Asked by At

I have a pickerView with dynamically changing number of rows. I want to choose this count from my model in the main app target.

For example, //test target

#import <KIF/KIF.h>
#import "SearchModel.h" //import class from main target

@interface Acceptance_Tests : KIFTestCase
@property (nonatomic, strong) SearchModel * searchModel;

@end

@implementation Acceptance_Tests

-(void)test_01_SearchWithConditions
{
    self.searchModel = [[SearchModel alloc] init];

    [tester tapViewWithAccessibilityLabel:@"Search Library"];
    [tester tapViewWithAccessibilityLabel:@"type_pickerView"];

    //choose type
    for(int i = 0; i < self.searchModel.types.count; i++)
    {
        [tester waitForTappableViewWithAccessibilityLabel:@"Search"];
        [tester selectPickerViewRowWithTitle:[self.searchModel.types objectAtIndex:i]];
        [tester tapViewWithAccessibilityLabel:@"Search"];
    }
}

When I do Cmnd+U I get an error

 Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_SearchModel", referenced from:
      objc-class-ref in Acceptance_Tests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Also I can add SearchModel.m to the Compile Cources in the test target, but that means I must add all classes twice (in the main target and in the test target), mm. Any thoughts? Can I get access to the classes in main target by another way ?

2

There are 2 best solutions below

0
On

The compile error tells you what's wrong. You are running the KIF tests in x64 mode (check your architectures and valid architectures in build_settings. Do you have arm64 in there?) your target app probably doesn't have the same architecture settings.

To start, I would make sure the architecture settings are identical between your KIF test target and your app.

0
On

Tests, KIF tests as well, are bundled as part of a host application which is being tested. Make sure "Bundle Loader" under "Linking" and "Test Host" under "Testing", both in project's "Build settings", are set to your application binary. If you've created your KIF Target as "iOS Unit Testing Bundle" this should be setup by default.