• 单元测试


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

  • 相关阅读:
    SpringMVC + MyBatis + Spring 开发思路记录
    毕设进度日记
    PIPI-OJ BUG log
    Codeforces Round #377 (Div. 2)
    图的基本遍历算法的实现(BFS & DFS)复习
    C语言题目复习前7章重点程序
    单链表实现
    二叉树-------二叉链表实现
    POJ3461 KMP 模板题
    编译原理词法分析 java简单实现
  • 原文地址:https://www.cnblogs.com/ycz25/p/6697421.html
Copyright © 2020-2023  润新知