[英]How run robolectric inside AOSP
I try run robolectric inside AOSP我尝试在 AOSP 中运行 robolectric
my Android.bp file looks like我的 Android.bp 文件看起来像
android_robolectric_test {
name: "MyRoboTests",
srcs: [
"src/**/*.java",
],
static_libs: [
"SettingsLib-robo-testutils",
"android-support-annotations",
"androidx.test.core",
"androidx.test.runner",
"androidx.test.ext.junit",
"androidx.test.espresso.core",
],
java_resource_dirs: ["config", "resources"],
instrumentation_for: "MyProject",
test_options: {
timeout: 36000,
shards: 10,
},
coverage_libs: [
"Settings-core",
"SettingsLib",
"SettingsLib-search",
],
}
test looks:测试看起来:
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class UsbTest {
@Test
public void test() {
Object object = new Object();
assertNotNull(object);
}
}
I try run with atest我尝试用 atest 运行
$ atest -c MyRoboTests
But test does not run.但是测试没有运行。 Out of console looks:控制台外的外观:
==================
Notice:
We collect anonymous usage statistics in accordance with our Content Licenses (https://source.android.com/setup/start/licenses), Contributor License Agreement (https://opensource.google.com/docs/cla/), Privacy Policy (https://policies.google.com/privacy) and Terms of Service (https://policies.google.com/terms).
==================
Finding Tests...
Found 'MyUsbTest' as MODULE
Running Tests...
Run 'atest --history' to review test result history.
Test does not work I don't understand What is wrong Could you help me with running robolectric for AOSP?测试不起作用我不明白出了什么问题你能帮我为 AOSP 运行 robolectric 吗?
After investigation, I have figured out that Robolectric isn't run with atest.经过调查,我发现 Robolectric 没有经过测试。
In google source documentation I found the link to readme: 在谷歌源文档中,我找到了自述文件的链接:
If the change is submitted to AOSP, then a unit test is required.如果将更改提交给 AOSP,则需要进行单元测试。 To get more information about how to write Robolectric based tests, see the readme file packages/apps/Settings/tests/robotests/README.md.要获取有关如何编写基于 Robolectric 的测试的更多信息,请参阅自述文件 packages/apps/Settings/tests/robotests/README.md。
Running a single test class运行单个测试类
$ croot
$ make RunSettingsRoboTests ROBOTEST_FILTER=<ClassName>
So in my sample I for my Android.bp file所以在我的示例中,我为我的 Android.bp 文件
//############################################################
// Settings Robolectric test target. #
//############################################################
android_robolectric_test {
name: "MyRoboTests",
srcs: [
"src/**/*.java",
],
static_libs: [
"SettingsLib-robo-testutils",
"android-support-annotations",
"androidx.test.core",
"androidx.test.runner",
"androidx.test.ext.junit",
"androidx.test.espresso.core",
],
java_resource_dirs: ["config", "resources"],
instrumentation_for: "MyProject",
test_options: {
timeout: 36000,
shards: 10,
},
}
To create a command I need to add "Run" to the module name "MyRoboTests"要创建命令,我需要将“运行”添加到模块名称“MyRoboTests”
$ make RunMyRoboTests ROBOTEST_FILTER=UsbTest
Note this!注意这一点!
You should correct create folders structure for roblectrics test like this :您应该更正为 robletrics 测试创建文件夹结构,如下所示:
Do not forget for "src" package inside "robotests" package.不要忘记“robottests”包中的“src”包。
After running tests I get the output:运行测试后,我得到输出:
============================================
[100% 10/10] build out/target/product/generic_car_x86_64/obj/ROBOLECTRIC/RunMyBoboRoboTests0_intermediates/test.fake
RunMyBoboRoboTests0:
RunMyBoboRoboTests0: Time: 15.395
RunMyBoboRoboTests0:
RunMyBoboRoboTests0: OK (12 tests)
RunMyBoboRoboTests0:
to open result files:打开结果文件:
$ nautilus out/target/product/generic_car_x86_64/obj/ROBOLECTRIC/RunMyBoboRoboTests0_intermediates/
I hope this helps someone.我希望这可以帮助别人。 Happy coding!快乐编码!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.