android 测试
2016-03-11 11:55
585 查看
官方:
https://developer.android.com/studio/test/index.html https://developer.android.com/training/testing/start/index.html https://github.com/dongdaqing/TestingExample
android 测试框架选择http://www.codeceo.com/article/5-android-test-framework.html
https://github.com/googlesamples/android-testing
1.android-testing-master\unit\BasicSample 第一个:
软件功能描述:
把名字,生日,email,作为一组数,用SharedPreferences保存。revert可以恢复上一次保存的。
test内容:
email格式:不能有空,"", 有com, 有.com。写法很简单:
保存SharedPreferences功能:主要用到mockito。
http://blog.csdn.net/sanjay_f/article/details/50178215 http://blog.csdn.net/sdyy321/article/details/38757135/ 。脱离环境,隔离测试。
http://www.oschina.net/translate/mockito-a-great-mock-framework-for-java-development
因为要测保存功能。而不是测试SharedPreferences类。我们也不关心SharedPreferences功能好不好。所以我们要模拟一个SharedPreferences功能,来测我们的保存功能。
我觉得这个比较有用啊。假设SharedPreferences是由别人完成的,功能还没完成,我们需要测试,所以要模拟一个存储功能。
今天先写到这。
D:\code\android-testing-master\unit\BasicUnitAndroidTest
似乎太简单
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/tongue.gif)
。
D:\code\android-testing-master\ui\uiautomator\BasicSample
有动的效果,ui测试。模拟点击按钮。效果很棒,很简单。
D:\code\android-testing-master\ui\espresso\BasicSampleBundled 有问题。
UIAutomator – is powerful and has good external OS system integration e.g. can turn WiFi on and off and access other settings during test, but lacks backward compatibility as it requires Jelly Bean or higher. But, also lacks detailed view access so one could
say it may be more of a pure black-box test. Where as Espresso has access to view internals (see below). This is recommended on developer.android.com for "Testing UI for Multiple Apps"
Espresso - is a bit more light weight compared to ui automator and supports 2.2 Froyo and up it also has a fluent api with powerful hamcrest(https://github.com/hamcrest)
integration making code more readable and extensible (it is newer than Ui automator). It does not have access to system integration tests but has access to view internals e.g. can test a webview (useful for Hybrid app testing, or webview heavy testing). Slightly
more grey-box testing compared to UI Automator. This is recommended on developer.android.com for "Testing UI for a Single App". As of Android Studio 2.2 this now offers UI test recording (like UIAutomator)
https://developer.android.com/studio/test/index.html https://developer.android.com/training/testing/start/index.html https://github.com/dongdaqing/TestingExample
android 测试框架选择http://www.codeceo.com/article/5-android-test-framework.html
https://github.com/googlesamples/android-testing
1.android-testing-master\unit\BasicSample 第一个:
软件功能描述:
把名字,生日,email,作为一组数,用SharedPreferences保存。revert可以恢复上一次保存的。
test内容:
email格式:不能有空,"", 有com, 有.com。写法很简单:
@Test public void emailValidator_EmptyString_ReturnsFalse() { assertFalse(EmailValidator.isValidEmail("")); }
保存SharedPreferences功能:主要用到mockito。
http://blog.csdn.net/sanjay_f/article/details/50178215 http://blog.csdn.net/sdyy321/article/details/38757135/ 。脱离环境,隔离测试。
http://www.oschina.net/translate/mockito-a-great-mock-framework-for-java-development
因为要测保存功能。而不是测试SharedPreferences类。我们也不关心SharedPreferences功能好不好。所以我们要模拟一个SharedPreferences功能,来测我们的保存功能。
我觉得这个比较有用啊。假设SharedPreferences是由别人完成的,功能还没完成,我们需要测试,所以要模拟一个存储功能。
今天先写到这。
D:\code\android-testing-master\unit\BasicUnitAndroidTest
似乎太简单
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/tongue.gif)
。
D:\code\android-testing-master\ui\uiautomator\BasicSample
有动的效果,ui测试。模拟点击按钮。效果很棒,很简单。
public void testChangeText_sameActivity() { // Type text and then press the button. mDevice.findObject(By.res(BASIC_SAMPLE_PACKAGE, "editTextUserInput")) .setText(STRING_TO_BE_TYPED); //输入框,输入字符串 mDevice.findObject(By.res(BASIC_SAMPLE_PACKAGE, "changeTextBt")) //点击按钮 .click(); // Verify the test is displayed in the Ui UiObject2 changedText = mDevice .wait(Until.findObject(By.res(BASIC_SAMPLE_PACKAGE, "textToBeChanged")), 500 /* wait 500ms */); //得到输出框 assertThat(changedText.getText(), is(equalTo(STRING_TO_BE_TYPED))); }
D:\code\android-testing-master\ui\espresso\BasicSampleBundled 有问题。
UIAutomator – is powerful and has good external OS system integration e.g. can turn WiFi on and off and access other settings during test, but lacks backward compatibility as it requires Jelly Bean or higher. But, also lacks detailed view access so one could
say it may be more of a pure black-box test. Where as Espresso has access to view internals (see below). This is recommended on developer.android.com for "Testing UI for Multiple Apps"
Espresso - is a bit more light weight compared to ui automator and supports 2.2 Froyo and up it also has a fluent api with powerful hamcrest(https://github.com/hamcrest)
integration making code more readable and extensible (it is newer than Ui automator). It does not have access to system integration tests but has access to view internals e.g. can test a webview (useful for Hybrid app testing, or webview heavy testing). Slightly
more grey-box testing compared to UI Automator. This is recommended on developer.android.com for "Testing UI for a Single App". As of Android Studio 2.2 this now offers UI test recording (like UIAutomator)
相关文章推荐
- IPC机制---04 Android中的IPC通讯方式(D)
- 设计模式_策略模式
- Android之MVC设计模式
- Android Color Generator
- 史上最详细的Android Studio系列教程(转载)
- Android 使用SVN
- Android 弹无虚发之第四弹:你应该掌握的Notification(Notification的通知栏常驻、Notification的各种样式、Notification点击无效)
- Android Library项目导出aar
- Makefile 中:= ?= += =的区别
- 适配 Android N 需要注意什么
- Android listview设置多个不同的item样式
- Android解惑 - 为什么要用Fragment.setArguments(Bundle bundle)来传递参数
- Android利用广播监听设备安装和卸载应用程序
- ViewConfiguration 介绍
- androidUSB通信——打印机
- androidUSB通信——打印机
- Android性能调优具体技巧 20+条(干货不止一点点)
- Android开发之px、dp、dip、sp
- Android仿美团下拉菜单(商品选购)实例代码
- Android工具类之时间日期格式化代码大全