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

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

  • 相关阅读:
    第一天课程总结与心得体会
    面对一切新的事物。
    libgdx学习记录3——动画Animation
    Eclipse编辑器设置
    libgdx学习记录2——文字显示BitmapFont
    libgdx自制简易Flappy Bird
    libgdx学习记录1——图片显示Texture
    libgdx自制简易版Don't Touch The White Tile
    eclipse 最最最常用快捷键
    libgdx退出对话框
  • 原文地址:https://www.cnblogs.com/liqianyi/p/6639426.html
Copyright © 2011-2022 走看看