如何在Android Studio使用Espresso框架自动化测试

1,Open your app's build.gradle file. This is usually not the top-level build.gradle file but app/build.gradle. Add the following lines inside dependencies:

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

androidTestCompile 'com.android.support.test:runner:0.5'

2,Set the instrumentation runner, add to the same build.gradle file the following line in android.defaultConfig:

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

3,Add the first test in src/androidTest/java/

@RunWith(AndroidJUnit4.class)

@LargeTest

public class HelloWorldEspressoTest {

      @Rule

      public ActivityTestRule<MainActivity>mainActivity = new ActivityTestRule(MainActivity.class);

      @Test

      public void TestElement(){

              onView()... 

     }

}

4,Create a test configuration, Run menu - Edit Configurations - Add a new Android Tests configuration - Choose a module - Add a specific instrumentation runner (android.support.test.runner.AndroidJUnitRunner)


参考文件:

https://google.github.io/android-testing-support-library/docs/espresso/setup/index.html


关于Android Studio 的安装和使用:

http://www.open-open.com/lib/view/open1468118887690.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值