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)));
    }

  • 相关阅读:
    博客园样式设置
    最坏情况为线性时间的选择算法
    棋盘覆盖
    矩阵乘法的Strassen算法及时间复杂度
    大整数乘法及算法时间复杂度
    全排列问题的递归算法(Perm)
    python的lambda
    python的zip函数
    python操作队列
    mysql基础命令
  • 原文地址:https://www.cnblogs.com/ycz25/p/6697421.html
Copyright © 2011-2022 走看看