zoukankan      html  css  js  c++  java
  • #单元测试

    **xml布局**

    、、、

            <TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!" />
    <EditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
    <Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="SAY HFLLO"
    android:onClick="sayHello"/>

    、、、
    **MainActivity.java**
    、、、
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    }

    public void sayHello(View view){
    TextView textView= (TextView) findViewById(R.id.textView);
    EditText editText= (EditText) findViewById(R.id.editText);
    textView.setText("Hello,"+editText.getText().toString()+"!");
    }
    、、、
    **环境配置**
    、、、
    //add for test
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    //add for test
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    }
    **测试**
    、、、
    public class MainActivityTest {
    private static final String STRING_TO_BE_TYPED = "Peter";
    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class);

    @Test
    public void sayHello() {
    onView(withId(R.id.editText))
    .perform(typeText(STRING_TO_BE_TYPED),
    closeSoftKeyboard());

    onView(withText("Say hello!")).perform(click());

    String expectedText = "Hello," + STRING_TO_BE_TYPED + "!";
    onView(withId(R.id.textView))
    .check(matches(withText(expectedText)));
    }
    、、、



  • 相关阅读:
    内存溢出和内存泄漏的区别
    java 23种设计模式 深入理解
    关于安装office注册表权限的解决方法
    Tomcat在Linux上的安装与配置
    初窥Linux 之 我最常用的20条命令
    redis使用初体验
    学习进度条——第12周
    找水王
    学习进度条——第11周
    学习进度条——第10周
  • 原文地址:https://www.cnblogs.com/huangxi1234/p/6567695.html
Copyright © 2011-2022 走看看