zoukankan      html  css  js  c++  java
  • Android的测试

    一个简单的Android界面

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.sam.a.MainActivity"
    android:orientation="vertical">
    <TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:textSize="25dp"
    android:id="@+id/textView"/>
    <EditText android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Enter your name here"
    android:id="@+id/editText"/>
    <Button android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="SAY HELLO"
    android:id="@+id/button"
    android:layout_gravity="center_horizontal" />
    </LinearLayout>

    Java代码
    package com.example.sam.a;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.TextView;
    public class MainActivity extends AppCompatActivity {
    @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);
    extView.setText("Hello,"+editText.getText().toString()+"!");
    }
    }


    测试代码

    public class MainActivityInstrumentation {  
       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(withId(
       R.id.btn)).perform(click());      
       String expectedText="Hello,"+STRING_TO_BE_TYPED+"!";    
         onView(withId(
       R.id.textview)).check(matches(withText(expectedText)));   
       }
    }
    
    
    
    
  • 相关阅读:
    软件的结构
    SpringMVC返回值类型及响应数据类型
    mybatis学习日记3
    面试八
    面试七
    微信小程序实例源码大全下载
    dot.js模板引擎,避免大量拼接字符串
    前端重构方案了解一下
    微信小程序开发基础教程
    如何让签到成为提升用户活跃度的利器
  • 原文地址:https://www.cnblogs.com/34nxy/p/6581158.html
Copyright © 2011-2022 走看看