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)));   
       }
    }
    
    
    
    
  • 相关阅读:
    找工过程中碰到的笔试面试题整理(1)
    windows核心编程学习笔记(五.续)堆
    windows核心编程学习笔记(二)Wait For Kernel Object(s)
    windows核心编程学习笔记(四)windows内存结构/虚拟内存/线程的堆栈
    [转]筛选法求素数
    windows核心编程学习笔记(五)内存映射文件
    windows核心编程学习笔记(八)结构化异常处理(Structured Exception Handling)
    [转]亲密接触VC6.0编译器
    windows核心编程学习笔记(三)线程池(Thread Pooling)
    windows核心编程学习笔记(七)DLL Injection and API Hooking
  • 原文地址:https://www.cnblogs.com/34nxy/p/6581158.html
Copyright © 2011-2022 走看看