简体   繁体   English

为什么Robolectric的第一次测试需要这么长时间?

[英]Why is does the first test run with Robolectric taking so long?

I'm testing my Android app with Robolectric but I faced a weird situation. 我正在使用Robolectric测试我的Android应用程序,但我遇到了一个奇怪的情况。 What happens is that when I run some set of tests, the first test ran with Robolectric takes much more time than any other test. 会发生的事情是,当我运行一些测试时,使用Robolectric进行的第一次测试比其他测试花费的时间要多得多。 It is not specific from the test itself, since I tried different configurations on the order of the tests and the result is that the first test is always the slowest. 它不是来自测试本身,因为我尝试了测试顺序的不同配置,结果是第一次测试总是最慢的。

Is it any Robolectric setup time or something like that? 是Robolectric的设置时间还是类似的东西? Any information provided is useful. 提供的任何信息都很有用。

For example: 例如: 慢速首次测试的示例

Yes, this is setup time. 是的,这是设置时间。 Unfortunately there are no central place where you can gather all information about Robolectric . 不幸的是,没有中心位置可以收集有关Robolectric所有信息。

Watch this presentation and you will find more explanations on pages 28, 29, 30, 35. 观看此演示文稿 ,您将在第28,29,30,35页找到更多解释。

If you're interested the Robolectric changed some approaches in version 2.0. 如果你有兴趣, Robolectric在2.0版本中改变了一些方法。 Significant changes are: 重大变化是:

  1. Javaassist usage replaced with ASM usage - for speedup start time Javaassist用法替换为ASM用法 - 用于加速开始时间
  2. They try to reduce number of shadow classes and use ASOP Android code instead - for better test reliability 他们尝试减少阴影类的数量并使用ASOP Android代码 - 以获得更好的测试可靠性

If you use gradle then take a look also on robolectric gradle plugin . 如果你使用gradle那么看看robolectric gradle插件 The added running tests in parallel and other tuning options. 并行添加的运行测试和其他调整选项。 The running tests in parallel apparently useful only with big amount of tests (hundreds+) 并行运行测试显然只对大量测试有用(数百+)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM