samedi 25 avril 2015

Why "Cannot find interface declaration for XCTestCase" in Swift unit test?

I added a Swift class to an ObjC project and wanted to write some unit tests for it. But when I go to build, XCode complains that it can't find the interface declaration for XCTestCase, even though the @import of XCTest is just above. What am I doing wrong?

Here is the relevant part of the generated -FooTests-Swift.h file, with annotations:

#if defined(__has_feature) && __has_feature(modules)
@import ObjectiveC;
@import XCTest;                <<<< Note the import
#endif

#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
#pragma clang diagnostic ignored "-Wduplicate-method-arg"

SWIFT_CLASS("_TtC12play611Tests14WeightedSumIn2")
@interface WeightedSumIn2 : NSObject   <<<< Error here: Cannot find
                                       <<<< interface declaration for 'XCTestCase'
- (SWIFT_NULLABILITY(nonnull) instancetype)initWithInitValue:(double)initValue OBJC_DESIGNATED_INITIALIZER;
- (double)push:(double)e;
@end

@class NSInvocation;

SWIFT_CLASS("_TtC12play611Tests18WeightedSumIn2Test")
@interface WeightedSumIn2Test : XCTestCase
- (void)test1;
- (SWIFT_NULLABILITY(null_unspecified) instancetype)initWithInvocation:(NSInvocation * __null_unspecified)invocation OBJC_DESIGNATED_INITIALIZER;
- (SWIFT_NULLABILITY(null_unspecified) instancetype)initWithSelector:(SEL __null_unspecified)selector OBJC_DESIGNATED_INITIALIZER;
- (SWIFT_NULLABILITY(nonnull) instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

Here is the source for the test case:

import UIKit
import XCTest

class WeightedSumIn2Test : XCTestCase {
    func test1() {...}
}

and for the class:

import UIKit

public class WeightedSumIn2 : NSObject {
    init(initValue: Double = 0.0) {...}
    func push(e: Double) -> Double {...}
}

Any idea what's wrong?

Aucun commentaire:

Enregistrer un commentaire