LoginSignup
1
0

More than 5 years have passed since last update.

[めも]Android Studioで、テスト(androidTestの方)する時に出るエラー

Posted at

意外とはまるので、めも。

エラー:zero-argument constructorの方

コードの自動生成で起こりがちなエラー。

表示されるエラー:

java.lang.Exception: Test class should have exactly one public zero-argument constructor

対処法: 引数なしの(デフォルト)コンストラクタを作る。

CalculatorInstrumentationTest() {
    super(CalculatorActivity.class);
}

サンプルコード全体は、Testing Support Library / AndroidJUnitRunner / JUnit サポート を参照して下さい。※そのままでは動きません。
(動かすためにコンストラクタを作ろうとしてはまるエラーですが・・)

原因: コードを自動生成すると、引数付きのコンストラクタが生成されるので。

自動生成されたコードの例 (エラーが発生します)

CalculatorInstrumentationTest(final Class<CalculatorActivity> cls) {
    super(cls);
}

参考:

Stackoverflow - Why is the Android test runner reporting “Empty test suite”?


エラー:Empty test suiteの方

テストの設定がおかしいと発生するエラー。

表示されるエラー:

Test running failed: Unable to find instrumentation info for: ・・・
Empty test suite.

対処法: テストの設定を変更する

1.Run / Edit Configurations...
2.Android Testsなどの下にある、各テストの設定を開く
3.General / Specific instrumentaion runner (optional)の設定を、AndroidJUnitRunnerに変更する。
※通常は、デフォルトでこの設定になっているはずです。

参考:

AndroidのTestまとめ
直ぐにテストを実行できない問題にはまる のあたりを参照。

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