android 测试

官方:

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

似乎太简单吐舌头


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)











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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值