title: Parametrized test tasks in Gradle
body: <p>I have some standalone test code (using Spock, in case it matters), which I need to pass a parameter into.</p>
  
  <p>Currently, I have a minimal <code>build.gradle</code> script which takes advantage of the fact that gradle will automatically generate a <code>test</code> task, so I pass my parameter into the tests as a system property using the following clause:</p>
  
  <pre><code>test {
      systemProperties = [serviceName:serviceName]
  }
  </code></pre>
  
  <p>With that, I can pass the parameter as a project parameter to Gradle, e.g.</p>
  
  <pre><code>gradle -PserviceName=SomeServiceName test
  </code></pre>
  
  <p>This does work, but I'm not too happy with it. There are only a known number of valid parameter values, so I'd like to have these pre-defined for the user, ideally as separate Gradle tasks, e.g. to be able to run:</p>
  
  <pre><code>gradle testSomeService
  gradle testSomeOtherService
  </code></pre>
  
  <p>where in my <code>build.gradle</code> I would define these tasks to set the property to a given value and then call <code>test</code>. Is there a 'nice' way to do this?</p>