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

来源:互联网 发布:亩和平方米精准算法 编辑:程序博客网 时间:2024/06/04 20:12

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


0 0
原创粉丝点击