gpt4 book ai didi

android - 为Android studio中的单元测试配置测试文件夹

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:59:39 27 4
gpt4 key购买 nike

我在我的 android studio 项目中添加了一个用于单元测试的文件夹。默认文件夹是 andoidTest 但我在 test 中添加了一个新文件夹和名称。 ( like robolectric sample tests )

当我在 build.gradle 下的模块中添加测试依赖时,例如

testCompile("junit:junit:${junitVersion}")
testCompile ("org.robolectric:robolectric:${robolectricVersion}")

它们不会添加到项目下的外部库中,但是当我使用默认配置并使用 androidTestCompile 时,它可以添加外部库。

然后我想也许我应该为 gradle 中的测试设置 Root,所以我在 build.gradle 的 android 标签中使用了以下内容:

sourceSets {
androidTest.setRoot('src/test')
}

但问题依然存在。我可以使用 gradlew 运行测试,但测试文件夹中的类中的导入不适用,也没有用于测试目的的外部库可见。

谁有解决这个问题的方法?

最佳答案

我正在搜索,但没有找到我认为已经涵盖的答案。因此决定为 future 创造一个新的。

回答Android Studio 现在不会自动获取单元测试。我知道它计划用于 1.3 版本。

因此,您必须在 Build Variants 工具窗口中将测试 Artifact 值从 Android Instrumental Tests 更改为 Unit Tests: enter image description here

关于android - 为Android studio中的单元测试配置测试文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31116598/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com