【问题标题】:Local Unit Test Android本地单元测试 Android
【发布时间】:2016-08-10 09:05:52
【问题描述】:

有人可以给我看一个工作代码来对此代码进行单元测试吗?

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome);
}

请告诉我使用本地单元测试(roboelectric.. 等,如果可能的话)和仪器测试。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout      xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

<Button
    android:id="@+id/login"
    android:text="Login"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

</LinearLayout>

显然,测试将检查是否有一个带有文本的按钮 Login 创建。

【问题讨论】:

标签: android unit-testing android-instrumentation


【解决方案1】:

使用Expresso:

if(onView(withText("Login")).exists()){ 
    doSomething(); 
} else { 
   doSomethingElse(); 
}

这里是details,了解如何使用 Expresso 进行设置。

【讨论】:

  • 我如何学习在上述框架中集成junit和mockito
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多