我是Android新手,我看过使用这些注释的示例代码。例如:
@SmallTest
public void testStuff() {
TouchUtils.tapView(this, anEditTextView);
sendKeys("H E L P SPACE M E PERIOD");
assertEquals("help me.", anEditTextView.getText().toString());
}
那个注释有什么作用?
This blog post解释得最好。基本上,它是以下内容:
根据Android Developers blog,小测试应该<100ms,中等测试<2s,大测试<120s。
有关如何指定运行哪些测试的信息,请参阅this page(搜索“@SmallTest”)。
作为评论中Davidann's answer和OP's question的补充:
在上面的代码的上下文中,除了为其他开发人员留下注释之外,它实际上做了什么吗?它执行什么吗?有没有使用此注释的工具? Android开发的目的是什么?
您可以运行一组使用特定注释注释的测试。
来自AndroidJUnitRunner documentation:
运行特定的测试大小,即使用SmallTest或MediumTest或LargeTest进行注释:
adb shell am instrument -w -e size [small | medium | large] com.android.foo/android.support.test.runner.AndroidJUnitRunner
您也可以通过gradle设置这些参数:
android {
...
defaultConfig {
...
testInstrumentationRunnerArgument 'size', 'Large'
}
}
有关详细信息,请参阅this blog post。
您还可以通过定义自己的@Category(MediumTest.class)
来使用@Category(LargeTest.class)
或Categories等注释POJO单元测试 - 请参阅test-categories repo以获取示例