android 自動化測試 Junit 中使用intent
阿新 • • 發佈:2021-01-10
技術標籤:Android
在Android中使用junit測試時,
在local test中,
不需要測試activity,但是類裡使用到intent的時候,可以這樣子取得intent
專案的junit,robolectric,請自行設定。
@RunWith(RobolectricTestRunner.class) public class SteraPaymentUtilTest { @Test public void test01() { //如此定義,即可取得intent Intent intent = new Intent(Robolectric.application.getApplicationContext(), Activity.class); } }
另外在顯示測試結果的時候,有時候會有亂碼
只需要在檔案(C:\Users\使用者名稱\.AndroidStudio4.0\config\studio64.exe.vmoptions)里加上編碼設定即可。
編碼設定追加方法,選擇選單「Help>Edit Custom VM Options..」
會開啟以下檔案,如果檔案不存在會自動建立。
貼上【-Dfile.encoding=UTF-8】即可
重啟Android studio之後,顯示正常了。