2011年12月30日金曜日

ActivityInstrumentationTestCase2

 I try JUnit.


Target Activity.

There is only button. I check logcat whether button is pushed.
Button button = (Button)findViewById(R.id.button1);

button.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
  Log.d("test", "button1");
 }
});
This is Tester. Only Button pushed.

setUp:get Activity and instrumentation.
mActivity = getActivity();
mInstrumentation = getInstrumentation();
test is button pushed. This must be no Errors.
public void testPushButton() throws Exception {
 
 final Button btnExecute = (Button)mActivity.findViewById(R.id.button1);
 
 mActivity.runOnUiThread(new Runnable() {
  public void run() {
   btnExecute.dispatchTouchEvent(MotionEvent.obtain(5,0, MotionEvent.ACTION_DOWN, 0, 0, 0));
   btnExecute.dispatchTouchEvent(MotionEvent.obtain(5,0, MotionEvent.ACTION_UP, 0, 0, 0));
   
  }
  
 });
 
 mInstrumentation.waitForIdleSync();
 
 assertEquals(true , true);
}

Test Start to select Tester 's "Android JUnit Test" like follow


It is result:



target source code is here.
Tester source code is here.

0 件のコメント:

コメントを投稿