title: How to switch/change testInstrumentationRunner dynamically with gradle
body: <p>My project has 2 different groups of tests. One group runs only with the default <code>AndroidJUnitRunner</code> the other has to be run with a custom implementation <code>TestRunner extends MonitoringInstrumentation</code>.</p>
  
  <p>Currently I switch the <code>testInstrumentationRunner</code> by editing the <code>build.gradle</code> each time I need to run the other group of tests:</p>
  
  <pre><code>android{
        defaultConfig {
            //testInstrumentationRunner "my.custom.TestRunner"
             testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
  }
  </code></pre>
  
  <p>I know that flavours can have their own <code>testInstrumentationRunner</code> but my current app already has 2 <code>flavourDimensions</code>. Using flavours is actually intended to have different versions of an app. I need 2 versions of the test application, both testing the same app with different <code>testInstrumentationRunner</code>s. </p>
  
  <p>I tried to change the <code>testInstrumentationRunner</code> by iterating over all test variants. There are actually multiple <code>testInstrumentationRunner</code> properties:</p>
  
  <pre><code>android.testVariants.all { TestVariant variant -&gt;
      //readonly
      variant.variantData.variantConfiguration.instrumentationRunner
  
      variant.variantData.variantConfiguration.defaultConfig.testInstrumentationRunner
  
  }
  </code></pre>
  
  <p>But as soon as <code>android.testVariants</code> is called the build gets configured and all changes are not reflected in the build.</p>
  
  <p>How can I change the testInstrumentationRunner (from a gradle plugin) dynamically? </p>
  
  <p>I'd prefer to have 2 different gradle tasks, each using a different <code>testInstrumentationRunner</code> but testing the same variant. Because I intent to create a gradle plugin the solution should work as plugin too.</p>