Android单元测试– JUnit4

In this tutorial, we’ll discuss Android Unit testing which forms an integral part of Android Application Development. We’ll specifically implement local Unit Testing using JUnit4.

在本教程中,我们将讨论Android单元测试,它构成了Android应用程序开发的组成部分。 我们将特别使用JUnit4实现本地单元测试。

Android单元测试 (Android Unit Testing)

As the name says, Unit testing is testing every unit of your code.

顾名思义,单元测试就是测试代码的每个单元。

Unit testing is a must to build robust applications. It is an important element while building quality applications.

要构建可靠的应用程序,必须进行单元测试。 这是构建高质量应用程序时的重要元素。

Unit testing consists of test cases which are used to check the business logic of your code.
Many times when you have been asked to or plan to add a feature in a working application just to realize that it broke some other part of your code. It’s too much to perform all the tests manually everytime when you refactor your code or add new things in it. This is where Unit Testing comes to our rescue.

单元测试由测试用例组成,这些用例用于检查代码的业务逻辑。
很多时候,当您被要求或计划在正在运行的应用程序中添加功能时,只是意识到它破坏了代码的其他部分。 每次在重构代码或向其中添加新内容时,手动进行所有测试都是太多了。 这就是单元测试为我们提供帮助的地方。

It performs quick automatic tests and alerts you if any test failed. You can quickly identify the issue.

它执行快速的自动测试,并在任何测试失败时提醒您。 您可以快速找出问题所在。

In general Testing is largely divided into the following types:

一般而言,测试大致分为以下几种类型:

  • Unit Tests

    单元测试
  • Integration Tests

    整合测试
  • UI Tests

    UI测试

Unit tests are the smallest (individually) and with the least execution time.

单元测试是最小的(单个)并且执行时间最少。

Following is an illustration quantifying each of the testing types from the Google Docs:

以下是量化Google文档中每种测试类型的图示:

Following are some of the testing frameworks used in Android:

以下是Android中使用的一些测试框架:

  • JUnit

    JUnit的
  • Mockito

    莫基托
  • Powermock

    动力模拟
  • Robolectric

    robolectric
  • Espresso

    浓咖啡
  • Hamcrest

    Hamcrest

Whenever you start a new Android Studio Project, JUnit dependency is already present in the build.gradle(also Expresso Dependency).

每当您启动新的Android Studio项目时, build.gradle就已经存在JUnit依赖关系(也build.gradle Expresso依赖关系)。

In your Android Studio Project, the following are the three important packages inside the src folder:

在您的Android Studio项目中࿰

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值