5

Android 開発者では、すべてのテストの前に testPreconditions() メソッドが起動されることになっているのを見てきました。しかし、私のアプリ テストでは、通常のテストのように動作しています。すべてのテストの前に実行されるわけではありません。何か問題がありますか?

Android 開発者による testPreconditions() に関する説明は次のとおりです。

4

3 に答える 3

6

実際、testPreconditions()は単なる別の単体テストです。これは、ディエゴ・トレス・ミラノの本「AndroidApplicationTestingGuide」からの引用です。

" testPreconditionsメソッドこのメソッドは、テストを正しく実行するためのいくつかの初期条件をチェックするために使用されます。その名前にもかかわらず、このテストが他のテストの前に実行されることは保証されません。ただし、すべての前提条件を収集することをお勧めします。このカスタム名でテストします。」

ミラノ、ディエゴトーレス(2011-06-23)。Androidアプリケーションテストガイド(p.76)。PacktPublishing。キンドル版。

于 2012-03-26T13:44:35.597 に答える
1

Android SDK サンプルによると:

   The name 'test preconditions' is a convention to signal that if this
   test doesn't pass, the test case was not set up properly and it might
   explain any and all failures in other tests.  This is not guaranteed
   to run before other tests, as junit uses reflection to find the tests.
于 2015-01-29T15:15:30.177 に答える
0

正しいクラス (ActivityInstrumentationTestCase2) から継承していること、およびメソッドの署名が一致していることを確認してください。

public void testPreconditions()
于 2012-03-25T11:23:31.387 に答える