How to debug one robolectric unit test in Android Studio

I can debug my gradle android project if I run all unit tests by following these steps:

First configure the IDE with gradle Run / Debug configuration for unit testing using Robolectric and JUnit

  • in the IDE menu do: File / Preferences / Compiler / gradle: Uncheck "Use build in progress"
  • In IDE run: Run / Edit Configuration / + / Gradle
  • Enter the following details in the fields: Name: test, gradle project: ... / app / build.gradle, Tasks: test, Script parameters: --debug --stacktrace

Next, to run / debug tests from the IDE, run:

  • Select "test" from config
  • To run: Run / Run 'test'
  • Debug: run / debug 'test'

This allows me to run all tests in the debugger.

Now I'm looking for a way to do the same, but only for one specified test. Any suggestions how great it would be.

+3


source to share


1 answer


It depends on the version of gradle you are using. If you are using version 1.x add the following script parameter to your run config

-Dtest.single=<testfilename> 

      

eg.

-Dtest.single=MyTest

      

You don't need to worry about the file path - just the name of the file containing the test class, no trailing .java

If you are using gradle 2.x add the following script parameter to your run config



--tests <test class name>

      

eg.

--tests com.example.data.MyTest

      

or --tests * .MyTest

With wildcards, you can run not only one test, but a subset of your tests

--tests com.example.data.*

      

+2


source







All Articles