Androidで有効なjunitテストスイートを構築しようとしています。
私はJunitを初めて使用するため、ServiceTestCaseクラスの使用方法がわかりません。
getService()メソッドを機能させる方法がわかりません。nullを返します。だから私はstartServiceを介してそれを開始することにしました。それは動作しません。
手伝っていただけませんか ?
ありがとう
Androidで有効なjunitテストスイートを構築しようとしています。
私はJunitを初めて使用するため、ServiceTestCaseクラスの使用方法がわかりません。
getService()メソッドを機能させる方法がわかりません。nullを返します。だから私はstartServiceを介してそれを開始することにしました。それは動作しません。
手伝っていただけませんか ?
ありがとう
これはあなたがあなたのサービスをテストするために必要なものです
public class MyServiceTests extends ServiceTestCase<MyService> {
private static final String TAG = "MyServiceTests";
public MyServiceTests() {
super(MyService.class);
}
/**
* Test basic startup/shutdown of Service
*/
@SmallTest
public void testStartable() {
Intent startIntent = new Intent();
startIntent.setClass(getContext(), MyService.class);
startService(startIntent);
assertNotNull(getService());
}
/**
* Test binding to service
*/
@MediumTest
public void testBindable() {
Intent startIntent = new Intent();
startIntent.setClass(getContext(), MyService.class);
IBinder service = bindService(startIntent);
assertNotNull(service);
}
}
Androidのテストとテスト駆動開発に関する記事をいくつか書いたので、役立つと思います。http://dtmilano.blogspot.com/search/label/test%20driven%20developmentを確認して ください。
受け入れられた答えはもう機能しません。
ActivityInstrumentationTestCase2やServiceTestCaseなどのTestCaseは廃止され、ActivityTestRuleまたはServiceTestRuleが優先されます。
彼らは実際のドキュメントを更新するのを忘れたようです。