Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable android studio unit tests (androidTest)

I have imported an eclipse project into android studio

Somehow it figured out that another one of my eclipse projects contained unit-test code for the imported project

It brought in that code and put it in a src/androidTest dir

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?

Maybe its via a gradle setting? (This is my first exposure to gradle)

Maybe I just need to delete all the androidTest java files but this seems a bit final..

like image 849
bph Avatar asked Jan 27 '16 16:01

bph


3 Answers

Put this code into your app's gradle script:

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.

: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.

I hope, this ll help you.

like image 127
burakokur Avatar answered Nov 08 '22 18:11

burakokur


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.

Example:

@Ignore("This test will be ignored")
@Test
public void my_test_method() {
    // test code here...
}
like image 45
Sakiboy Avatar answered Nov 08 '22 18:11

Sakiboy


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.

enter image description here

Calling for rebuilding in Android Studio is just a UI for passing these tasks to gradle:

Gradle tasks [: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 androidTest directory
  • build project with Android plugin for Gradle and 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

I hope, it helps.

like image 38
Konstantin Loginov Avatar answered Nov 08 '22 18:11

Konstantin Loginov