我用下面的測試庫的Android應用程序:我可以分別測試Activities和Fragments的生命週期方法嗎?
androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'
我想,如果我現在在某種程度上可以分別測試onCreate()
- ,onStart()
- 和onResume()
- 方法。那麼是否有可能在某個測試用例中不調用其他方法的情況下調用其中一個方法?
爲什麼我要這樣做?在我的Activity
中,我在onCreate()
中創建Fragment
並將其應用於Activity
。但在onResume()
片段我設置的東西導致Fragment
Fragment
附加到Activity
另一個Fragment
。我想測試第一個片段是否加載。但在我的測試案例中onResume()
已被觸發,第一個片段被替換。所以我就想單獨測試onCreate()
。
你想在'onCreate'或其他方法中測試什麼? – mallaudin
@mallaudin我剛剛更新了我的帖子 – unlimited101