1
0

More than 1 year has passed since last update.

Realmモデルの単体テストで RLMObject subclasses with the same name cannot be included twice in the same target. Please make sure 'Employee' is only linked once to your current target.

Posted at

Realmのモデルの単体テストを追加したところ、テストを実行するとAppDelegateで以下のエラーが表示されテストがクラッシュするようになりました。

Thread 1: "RLMObject subclasses with the same name cannot be included twice in the same target. Please make sure 'Employee' is only linked once to your current target."

原因としてはRealm ObjectのサブクラスとしてEmployeeを定義していますが、そのEmployeeをアプリとテストの両方のTargetに追加していたのが、良くなかったようです。

今回RealmのObjectのサブクラスとしてEmployeeクラスをテスト対象としています。

ダメだった状態

  • Employeeクラスをアプリとテストの両方のターゲットに含めていた

テスト可能な状態

  • Employeeクラスはアプリのターゲットのみに含める
  • テストコードの先頭に以下のインポートを追加する @testable import アプリのターゲット名

このようにすることで、テストコードからEmployeeを参照することができ、Employeeはアプリ側のターゲットのみに含めることができます。

参考

本件とは直接関係ないんだけど、テストケースにアプリ側で必要なPodの依存がすべてふくまれちゃうんだよなぁ。
今回のケースだとRealmSwiftには依存していいけど、Firebaseとかの依存ははずしたいんだけど。。。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0