eclipse 如何禁用 android studio 单元测试 (androidTest)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35042779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable android studio unit tests (androidTest)
提问by bph
I have imported an eclipse project into android studio
我已经将一个 Eclipse 项目导入到 android studio
Somehow it figured out that another one of my eclipse projects contained unit-test code for the imported project
不知怎的,它发现我的另一个 Eclipse 项目包含导入项目的单元测试代码
It brought in that code and put it in a src/androidTest dir
它引入了该代码并将其放在 src/androidTest 目录中
I didn't really want it to do that but they are there now and causing the build to fail
我真的不希望它这样做,但它们现在在那里并导致构建失败
Is there a means to turn off the androidTest stuff? So I can concentrate on whether the app actually builds?
有没有办法关闭 androidTest 的东西?所以我可以专注于应用程序是否真正构建?
Maybe its via a gradle setting? (This is my first exposure to gradle)
也许它通过gradle设置?(这是我第一次接触gradle)
Maybe I just need to delete all the androidTest java files but this seems a bit final..
也许我只需要删除所有的 androidTest java 文件,但这似乎有点最终..
采纳答案by Konstantin Loginov
Once you do Rebuilding the project in Android Studio - all the source files in the project are recompiled. Plenty of different tasks start including :compileDebugAndroidTestJavaWithJavac
which is causing the build-break, once your Instrumental Tests are not compilable.
在 Android Studio 中重建项目后 - 项目中的所有源文件都会重新编译。:compileDebugAndroidTestJavaWithJavac
一旦您的仪器测试无法编译,就会开始许多不同的任务,包括哪些任务会导致构建中断。
Calling for rebuilding in Android Studio is just a UI for passing these tasks to gradle:
在Android Studio中调用rebuild只是将这些任务传递给gradle的UI:
Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:prepareDebugUnitTestDependencies, :app:mockableAndroidJar, :app:compileDebugSources, :app:compileDebugAndroidTestSources, :app:compileDebugUnitTestSources]
Gradle 任务 [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:prepareDebugUnitTestDependencies, :app:mockableAndroidJar, :app:compileDebugSources, :app:compileDebugAndroidTestSources, :app:compileDebugUnitTestSources]
I.e. there's no obvious way how can it be modified.
即没有明显的方法如何修改它。
Workarounds:
解决方法:
- comment out broken files in androidTest
- remove/rename androidTestdirectory
- build project with Android plugin for Gradleand passing all commands, apart from ones related to InstrumentalTests
- avoid Making/Rebuilding solution, just add(if it's not exist yet) Android Application configuration and build the app itself, without instrumental tests
- 在androidTest 中注释掉损坏的文件
- 删除/重命名androidTest目录
- 使用Android 插件为 Gradle构建项目并传递所有命令,除了与 InstrumentalTests 相关的命令
- 避免制作/重建解决方案,只需添加(如果尚不存在)Android 应用程序配置并构建应用程序本身,无需工具测试
I hope, it helps.
我希望,它有帮助。
回答by Sakiboy
Someone might find this useful: If you're using JUnit
there's an @Ignore
command you can put on a test method to ignore the entire test method.
有人可能会发现这很有用:如果您正在使用JUnit
有一个@Ignore
命令,您可以放置一个测试方法来忽略整个测试方法。
Example:
例子:
@Ignore("This test will be ignored")
@Test
public void my_test_method() {
// test code here...
}
回答by burakokur
Put this code into your app's gradle script:
将此代码放入应用程序的 gradle 脚本中:
tasks.whenTaskAdded { task ->
if (task.name.equals("lint")) {
//this is for speed up build
task.enabled = false
}
if(task.name.contains("Test"))
{
//this is what you need
task.enabled = false
}
}
When gradle add a task, this code ll check tasks name. if this task is 'lint' (check here) which is not need every build. if this task has a 'Task' word, we can skip if we want.
当 gradle 添加一个任务时,这段代码会检查任务名称。如果此任务是“lint”(在此处查看),则不需要每次构建。如果此任务有“任务”字样,我们可以跳过。
:app:preDebugAndroidTestBuild SKIPPED
:app:compileDebugAndroidTestAidl SKIPPED
:app:processDebugAndroidTestManifest SKIPPED
:app:compileDebugAndroidTestRenderscript SKIPPED
:app:generateDebugAndroidTestBuildConfig SKIPPED
:app:generateDebugAndroidTestResValues SKIPPED
:app:generateDebugAndroidTestResources SKIPPED
:app:mergeDebugAndroidTestResources SKIPPED
:app:splitsDiscoveryTaskDebugAndroidTest SKIPPED
:app:processDebugAndroidTestResources SKIPPED
:app:generateDebugAndroidTestSources SKIPPED
I dont know what these tasks are. But when i skip on my project doesnt effect anything but speed (not much because i dont have test files) which is a pain on gradle build system.
我不知道这些任务是什么。但是当我跳过我的项目时,除了速度(因为我没有测试文件,所以影响不大)这对 gradle 构建系统来说很痛苦。
I hope, this ll help you.
我希望,这会帮助你。