• 单元测试


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

  • 相关阅读:
    C# 收集几条ToString()格式
    C# 使用Quartz简单实例以及备忘
    C# Linq 常用查询操作符
    .Net Core 创建和使用中间件
    .Net Core 学习依赖注入自定义Service
    .Net Core 学习路由和请求参数传递
    .Net Core 学习新建Core MVC 项目
    ExtJS笔记5 Components
    ExtJS笔记4 容器与布局(Layouts and Containers)
    ExtJS笔记3 MVC Architecture
  • 原文地址:https://www.cnblogs.com/yzj40/p/6637997.html
Copyright © 2020-2023  润新知