你的位置:首页 > 软件开发 > 操作系统 > Building Local Unit Tests

Building Local Unit Tests

发布时间:2016-07-18 18:00:05
If your unit test has no dependencies or only has simple dependencies on Android, you should run your test on a local development machine. T ...

Building Local Unit Tests

If your unit test has no dependencies or only has simple dependencies on Android, you should run your test on a local development machine. This testing approach is efficient because it helps you avoid the overhead of loading the target app and unit test code onto a physical device or emulator every time your test is run. Consequently, the execution time for running your unit test is greatly reduced. With this approach, you normally use a mocking framework, like Mockito, to fulfill any dependency relationships.

Set Up Your Testing Environment


In your Android Studio project, you must store the source files for local unit tests at module-name/src/test/java/. This directory already exists when you create a new project.

You also need to configure the testing dependencies for your project to use the standard APIs provided by the JUnit 4 framework. If your test needs to interact with Android dependencies, include theMockito library to simplify your local unit tests. To learn more about using mock objects in your local unit tests, see Mocking Android dependencies.

In your app's top-level build.gradle file, you need to specify these libraries as dependencies:

dependencies {public class EmailValidatorTest {    @Test@RunWith(MockitoJUnitRunner.class)    private static final String FAKE_STRING = "HELLO WORLD";    @Mock    @Test        // ...when the string is returned from the object under test...        // ...then the result should be the expected one.

原标题:Building Local Unit Tests

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录