设置:
我继承的一个较旧的项目有很多遗留的仪器测试,我想对它们施加超时,因为它们中的很多都可以无限期地挂起,这使得很难获得测试报告。我正在将测试更新为 Junit4 样式,但目前它们都在扩展 ActivityInstrumentationTestCase2。
到目前为止尝试过:
在 AndroidJUnitRunner 的文档中它说要设置这个标志:
Set timeout (in milliseconds) that will be applied to each test: -e timeout_msec 5000 ...
... All arguments can also be specified in the in the AndroidManifest via a meta-data tag
我已经尝试将 AndroidJUnitRunner 配置添加到应用程序 list 和测试 list 中,但 timeout_msec 元数据项到目前为止没有任何效果。
最佳答案
您可以使用规则为类中的每个测试提供超时,如下所示。
@Rule public Timeout timeout = new Timeout(120000, TimeUnit.MILLISECONDS);
您还可以使用以下命令指定每个测试基础超时
@Test(timeout = 100) // Exception: test timed out after 100 milliseconds
public void test1() throws Exception {
Thread.sleep(200);
}
您可以使用此链接阅读更多关于差异的信息
https://stackoverflow.com/a/32034936/2128442
关于android-instrumentation - AndroidJUnitRunner + ActivityInstrumentationTestCase2 超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40052862/