android test

Edit

http://stackoverflow.com/questions/2762665/how-to-use-emma-code-coverage-in-android

http://developer.android.com/guide/developing/projects/projects-cmdline.html

http://developer.android.com/guide/developing/building/building-cmdline.html

Instrumentation 의미

http://markmail.org/message/q77wqlmjsu5ffztf

System <-> Application 사이에서 일어나는 모든 상호작용에 대해서 감시가 가능. 모든 상호작용에 대해서 감시가 가능하기 때문에 Application이 실행되기 전에 미리 만들어지는게 당연하다. 같은 이유로 code에 들어가는 것이 아니라 http://jeyong.com/MoinMoin/ns/moin.cgi/AdnroidManifest[?]AdnroidManifest.xml에 선언되어야 한다.

http://dtmilano.blogspot.com/2011/08/linuxcon-2011-north-america.html

테스트 실행

전체: adb shell am instrument -w com.example.aatg.myfirstproject.test/android.test.InstrumentationTestRunner

하나만: adb shell am instrument -w -e class com.example.aatg.myfirstproject.test.MyFirstProjectTests com.example.aatg.myfirstproject.

test/android.test.InstrumentationTestRunner

사례

카카오톡 임유진 님 ( eugenelgm@gmail.com )의 발표

추천자료

http://www.slideshare.net/dtmilano/testing-on-android

http://dtmilano.blogspot.com/2011/08/linuxcon-2011-north-america.html

http://jeyong.com/MoinMoin/ns/moin.cgi/AndroidJUnit

http://jeyong.com/MoinMoin/ns/moin.cgi/AndroidJUnit

http://jeyong.com/MoinMoin/ns/moin.cgi/AndroidJUnit

http://dtmilano.blogspot.com/search/label/junit

http://mihaifonoage.blogspot.com/2010/01/unit-and-functional-testing-in-android.html

https://sites.google.com/site/androiddevtesting/

Activity.finish(), and restarts it using the instrumentation method getActivity()

onPause() and onResume()

Instrumentation mInstr = this.getInstrumentation();

mInstr.callActivityOnPause(mActivity);

@UiThreadTest@MediumTest

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com/[http://www.google.com]"));
startActivity(intent);

기본 메뉴얼

이클립스에서 안드로이드 JUnit Test 프로젝트 생성

안드로이드에서 단위테스트를 위한 Junit 사용하기 (1)

안드로이드에서 단위테스트를 위한 Junit 사용하기 (2)

http://developer.android.com/resources/tutorials/testing/helloandroid_test.html

안드로이드 테스트 - Hello, Testing

http://developer.android.com/guide/topics/testing/testing_android.html

안드로이드 테스트 - Testing and Instrumentation 소프트웨어

http://developer.android.com/resources/tutorials/testing/activity_test.html

http://developer.android.com/resources/tutorials/testing/activity_test.html

http://developer.android.com/resources/tutorials/testing/activity_test.html

번역 : http://blog.naver.com/huewu/110089695301 ,http://blog.naver.com/huewu/110089769967\[http://blog.naver.com/huewu/110089769967]

http://developer.android.com/resources/tutorials/testing/activity_test.html

Android JUnit vs JUnit 4

http://d.android.com/resources/tutorials/testing/activity_test.html

final EditText edittext = (EditText) findViewById(R.id.edittext);

http://d.android.com/reference/android/test/ServiceTestCase.html

https://sites.google.com/site/androiddevtesting/

http://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html

안드로이드 unit test 에서 async task 결과를 테스트하기

Android, Unit test 대상 로직에서 Handler 사용 시 멈추는 문제 해결

http://mobile.dzone.com/news/unit-and-functional-testing

mock 응용

http://stuffikeepforgettinghowtodo.blogspot.com/2008/12/android-mockito.html

http://stuffikeepforgettinghowtodo.blogspot.com/2008/12/android-mockito.html

http://stuffikeepforgettinghowtodo.blogspot.com/2008/12/android-mockito.html

Junit 하위 클래스

http://d.android.com/reference/android/test/package-summary.html

==== ActivityInstrumentationTestCase2

single activity에 대한 테스트

Activity를 system infrastructure에 의해서 만듬. 일반 시스템 환경

@UiThreadTest annotation과 함께 만듬

Activity가 다른 요소들과 잘 상호작용 하는지를 테스트

MockContext 사용 불가

Mock Intent 사용 가능

키, 터치 이벤트 전달 가능

setActivityTouchMode(false)

sendKeys

setActivityIntent

==== ApplicationTestCase

onCreate after createApplication()

tearDown calls onDestroy();

mockContext 삽입가능

terminatorApplication

==== ActivityUnitTestCase

1개 Activity의 고립된 테스트

System과의 interaction에 Activity가 참가할 수 없다

System과의 최소한도로 연결되어서 Activity가 생성

일부 메소드는 Exception

==== ProviderTestCase2

ContentProvider의 고립된 테스트

MockContentResolver 사용이 제한됨

IsolatedContext 사용.

==== ServiceTestCase

startService(Intent) 혹은 bindService(Intent)를 부르면 onCreate가 호출된다.

setApplication혹은 setContext()를 호출해서 Mock 주입가능

==== AndroidTestCase

custom view, permission 관련 테스트

권한, resource접근 테스트

==== ViewAsserts

==== TouchUtils

clickView()

longClick()

== Mock

http://d.android.com/reference/android/test/mock/package-summary.html

adb -e shell am instrument -w -e class com.benelogTouchActivityTests

==== 에러

http://code.google.com/p/android/issues/detail?id=14616

http://stackoverflow.com/questions/2634991/android-1-6-android-view-windowmanagerbadtokenexception-unable-to-add-window

http://stackoverflow.com/questions/2365561/testing-dialog-in-androids-activityunittestcase

unlock

http://stackoverflow.com/questions/3214531/how-to-send-key-events-to-a-headless-emulator-in-an-instrumentation-test/3366443#3366443

=== Robotium

ActivityInstrumentationTestCase : depreciated.

=== RoboElectric

=== Android Mock

  • CGLib등을 안 쓰는 EasyMock 2.4 이용. interface mocking만 가능.

=== Calabash

=== Spoon

  • 여러 Device에서 앱을 동시에 실행하고 스크린샷 제공

=== LMock

  • Jmock 스타일, Mockito 스타일 다 가능.
  • VMWare에서 만들었음. 문서화는 부족하나 예제는 잘 정리되어 있음.
  • 예제

=== ScalaMock

  • 전에는 Borachio
  • Mockito가 이제 Android 지원하므로 더 이상 나는 지원안한다고 쿨하게 밝힘.
  • Roboguice + Borachio 예제 프로젝트 https://github.com/jaley/borachio-warehouse
  • Android + ScalaMock 예제 설명

=== RoboSpec

== PowerMock