How to disable Android studio block tests (androidTest)

I imported the eclipse project to android studio

Somehow it turned out that another of my eclipse projects contained a unit test code for an imported project

He entered this code and placed it in the src / androidTest directory

I really didn’t want this to be done, but they are now and are causing build failures

Is there any way to disable androidTest stuff? So I can focus on whether the application really creates?

Maybe using the gradle parameter? (This is my first acquaintance with gradle)

Maybe I just need to delete all javas androidTest files, but that seems a bit final.

+5
source share
3 answers

Once you rebuilt the project in Android Studio, all the project source files will be recompiled. Many different tasks :compileDebugAndroidTestJavaWithJavac , including :compileDebugAndroidTestJavaWithJavac causing break-break as soon as your instrumental tests are not compiled.

enter image description here

The rebuild call in Android Studio is just an interface for transferring these tasks to gradle:

Gradle tasks [: app: generateDebugSources ,: application: generateDebugAndroidTestSources ,: app: prepareDebugUnitTestDependencies ,: app: mockableAndroidJar ,: app: compileDebugSources ,: app: compileDebugAndroidTestSources ,: Application: compileDebugUnitTnest]

those. There is no obvious way to change it.

Workarounds:

  • Comment on broken files in androidTest
  • delete / rename androidTest directory
  • build a project with an Android plugin for Gradle and pass all the commands except those related to InstrumentalTests
  • Avoid creating / restoring the solution, just add (if it does not already exist) the configuration of the Android application and create the application yourself without instrumental tests.

Hope this helps.

+5
source

Some might find this useful: if you use JUnit , there is a @Ignore command @Ignore that you can apply to the test method to ignore the entire test method.

Example:

 @Ignore("This test will be ignored") @Test public void my_test_method() { // test code here... } 
+2
source

Put this code in your gradle script application:

 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 adds a task, this code checks the name of the task. if this task is "lint" ( here), which does not need every assembly. if this task has the word "Task", 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 do not know what these tasks are. But when I skip my project, it does not affect anything but speed (not so much because I do not have test files), which is a pain in the gradle build system.

Hope this helps you.

+2
source

Source: https://habr.com/ru/post/1241636/


All Articles