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

    XML布局:

    <TextView
    android:text="Hello World"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView2"/>

    <Button
    android:text="Say Hello"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button"
    android:layout_marginTop="41dp"
    android:layout_below="@+id/textView2"
    android:layout_alignparentStart="true"
    android:onClick="Say Hello"/>


    <EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/editText"
    android:layout_below="@+id/textView2"
    android:layout_alignparentStart="true"
    android:layout_alignparentEnd="true"
    android:text="huanying"/>

    java代码:
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    }
    public SayHello(View v){
    TextView textView = (TextView)findViewById(R.id.textView);
    EditText editText = (EditText)findViewById(R.id.editText);
    TextView.setText("Hello,"+editText.getText().toString()+"!");
    }


    测试程序:

    @Rule
    public ActivityTestRule<MainActivity>mActivityRule = new ActivityTestRule<>(MainActivity.class);

    @Text
    public void sayHello(){
    onView(withId(R.id.editText)).perform(typeText(STRING_TO_BE_TYPED),closeSoftKeyboard());
    onView(withText("Say hello!")).perform(click());
    String expectedText = "Hello,"+STING_TO_BE_TYPED+"!";
    onView(withId(R.id.textView)).check(matches(withText(expectedText)));
    }

  • 相关阅读:
    第五章 Mybatis注解
    第四章 Mbatis高级查询
    第三章 Mybatis动态Sql
    第二章 Mybatis映射文件
    第一章 初识Mybatis
    Mybatis大纲设计
    项目总结
    第二周项目功能实现
    第一周项目功能实现
    客车网上售票系统需求分析
  • 原文地址:https://www.cnblogs.com/liqianyi/p/6639426.html
Copyright © 2011-2022 走看看