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

    1、界面布局

    <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"

        android:hint="Enter your name here"/>

    <Button

        android:id="@+id/button"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

       android:text="say hello"

       android:onClick="sayHello"/>

    2、MainActivity.java

    先声明定义:private TextView textView;private EditText  editText;private Button btn;

     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()+"!");

    }

    3、测试代码

     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
    Python运行异常 Original error was: DLL load failed:
    Python运行异常 Original error was: DLL load failed:
    数据标准化的方法与意义
    数据标准化的方法与意义
    神经网络为什么要归一化
    神经网络为什么要归一化
    梯度下降与delta法则
    梯度下降与delta法则
    from表格
  • 原文地址:https://www.cnblogs.com/zxw-1017/p/6580760.html
Copyright © 2011-2022 走看看