2017-09-11 7 views
0
import RealmSwift 

// MARK: Class 

/// The DataPoint object representation 
public class DataPoint: Object { 

    // MARK: - Variables 

    /// The latitude of the point 
    dynamic var lat: Double = 0 
    /// The longitude of the point 
    dynamic var lng: Double = 0 
    /// The accuracy of the point 
    dynamic var accuracy: Double = 0 

    /// The added point date of the point 
    dynamic var dateAdded: Date = Date() 
    /// The last sync date of the point 
    dynamic var lastSynced: Date? 
} 

私は上記の単純なレルムオブジェクトクラスを持っています。現時点ではRealmとは無関係にユニットテストをしたい。元々、このクラスのターゲットメンバーをすべてのターゲット(App、UnitTests、UITests)に設定しましたが、クラスの重複エラーが発生した後、そのレルムにはメインのアプリケーションターゲットのみが必要です。だから私はやったと私は提案されたようにクラスを公開しました。しかし、今ユニットテストの対象であっても、エラーでビルドされていません。レルムを使ったユニットテスト:宣言されていないタイプ

Undeclared Type 'DataPoint' 

任意のアイデアはどのように私は実際には、もちろん、すべてのターゲット・メンバーシップにクラスを追加せずにこのエラーを解決することができます。

答えて

1

ユニットテストターゲットにアプリケーションのクラスを追加する必要はありません。 Appターゲットは、ユニットテストターゲットに暗黙的にリンクされています。テストクラスで@testabe import App(またはpublicシンボルのみを使用する場合はimport App)を使用できます。ユニットテストターゲットの設定で、 "ホストアプリケーション"を選択し、 "一般"タブで "ホストアプリケーションAPIのテストを許可"をチェックしてください。 「ホストアプリケーション」が選択されていない場合、Xcodeはアプリケーションモジュールをユニットテストターゲットにリンクしません。

一方、UIテストではAppモジュールのAPIを使用できません。 UIテスト中は、テストクラスはアプリのコードにアクセスできないためです。

Apple's Docsから:

UI testing differs from unit testing in fundamental ways. Unit testing enables you to work within your app's scope and allows you to exercise functions and methods with full access to your app's variables and state. UI testing exercises your app's UI in the same way that users do without access to your app's internal methods, functions, and variables. This enables your tests to see the app the same way a user does, exposing UI problems that users encounter.

あなたはまだで、上記のように、それを失敗した場合は、設定に何か問題があります。調査のために問題を再現するためにプロジェクトを共有してください。

関連する問題