2012-02-29 12 views
2

ボタンをクリックしたときにボタンが正しい動作を開始するかどうかをテストするユニットテストを作成しようとしていますが、使用する。 testButton方法を実行して、テストに合格しない、しかしそれは、エラーが発生します。単体テストを使用してボタンが正しいアクティビティを起動することをテストする方法

[2012-02-29 16:18:08 - TroubleShootingAppTest] Test run failed: Instrumentation run failed due to 'java.lang.RuntimeException' 

テストは、早期に終了します。誰でも正しいコードが何であるべきかアドバイスできますか?

これは私が持っているものです。

package com.integral.troubleshooter.test; 

import com.integral.troubleshooter.Question; 
import com.integral.troubleshooter.R; 
import com.integral.troubleshooter.TroubleShooterActivity; 

import android.app.Activity; 
import android.content.Intent; 
import android.test.ActivityInstrumentationTestCase2; 
import android.text.Layout; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.Spinner; 
import android.widget.TextView; 

public class TroubleShooterActivityTest extends 
    ActivityInstrumentationTestCase2<TroubleShooterActivity> { 

private TroubleShooterActivity mActivity; 
private Button mButton; 
private TextView mTextView; 
private ImageView mImageView; 
private String resourceString; 
private Activity nextActivity; 

public TroubleShooterActivityTest() {  
    super("com.integral.troubleshooter.TroubleShooterActivity",  TroubleShooterActivity.class);  
} 

/* 
* Sets up the test environment before each test. 
* @see android.test.ActivityInstrumentationTestCase2#setUp() 
*/ 
@Override 
protected void setUp() throws Exception { 

    super.setUp(); 

    setActivityInitialTouchMode(false); 


    mActivity = getActivity(); 

    mButton = (Button)mActivity.findViewById(R.id.troubleShooter); 

    mTextView = (TextView)mActivity.findViewById(R.id.title); 

    mImageView = (ImageView)mActivity.findViewById(R.id.IntegralLogo); 

    resourceString = mActivity.getString(R.string.CustomerSupport); 
} 

public void testPreconditions() { 
    assertTrue(mTextView != null); 
    assertTrue(mImageView != null); 
} 

public void testText(){ 
    assertEquals(resourceString,(String)mTextView.getText()); 
} 

public void testButton(){ 
    mActivity.runOnUiThread(
       new Runnable() { 
        public void run() { 
         mButton.performClick(); 
         nextActivity = getActivity(); 
         assertEquals(nextActivity, Question.class); 
        } 
       } 
      ); 



} 
} 
+0

さらにスタックトレースを送信できますか? – yorkw

+0

yorkwに感謝しますが、私はRobolectricを使ってテストを実装することにしました。 – user

答えて

0

は、計装が存在しないかどうかを確認してください。このコマンドを実行すると、プロジェクトの環境では、本計器のリストが表示されます:

$ adb shell pm list instrumentation 

私はこのヘルプを願っています。

関連する問題