[GRADLE-133] support executing only a single junit task instead all junit tests Created: 03/Jul/08  Updated: 04/Jan/13  Resolved: 24/Nov/10

Status: Resolved
Project: Gradle
Affects Version/s: 0.2
Fix Version/s: 0.9-rc-1

Type: Improvement
Reporter: Marko Bauhardt Assignee: Hans Dockter
Resolution: Fixed Votes: 8


 Description   

in maven2 it is possible with the command

mvn test -Dtest=MyTest



 Comments   
Comment by Jon Cox [ 22/Jan/09 ]

What would you do above and beyond what you could do with something like:

test

{ include '**/*Test.class', '**/*Tests.class' exclude '**/Abstract*' // set forkmode to ONCE to reduce groovy startup time options.fork(forkMode: ForkMode.ONCE) }

Would you want to examine the value of a property and include/exclude stuff
conditionally based on that? If so, why not do it in the body of the test

{...}

closure ?

Am I not understanding the issue?

Comment by Marko Bauhardt [ 23/Jan/09 ]

i would like to execute only ONE junit test instead the complete test suite. for example i have three tests in my test folder

org.OneTest.java
org.TwoTest.java
org.ThreeTest.java

if i execute "gradle test" all three tests are running. but i want to be able to execute only TwoTest.java or maybe ThreeTest.java.
in maven it s possible with "mvn test -Dtest=TwoTest"

marko

Comment by Russel Winder [ 21/Sep/09 ]

This really needs to be possible without each developer having to write the task themselves – it is boilerplate code and Gradle should avoid people writing boilerplate code.

Comment by Dan Tanner [ 02/Aug/10 ]

What's the syntax for the fix?

Comment by Hans Dockter [ 03/Aug/10 ]

This is from the latest user's guide (which is not yet uploaded):

<section>
            <title>System properties</title>
            <para>There are two system properties that can affect test execution.  Both of these are based off
                  of the name of the test task with a suffix.
            </para>
            <para>Setting a system property of <replaceable>taskName.single</replaceable> = <replaceable>testNamePattern</replaceable>
                  will only execute tests that match the specified <replaceable>testNamePattern</replaceable>.
                  The <replaceable>taskName</replaceable> can be a full multi-project path like &quot;:sub1:sub2:test&quot;
                  or just the task name.  The <replaceable>testNamePattern</replaceable> will be used to form an include
                  pattern of &quot;**/testNamePattern*.class&quot;.
                  If no tests with this pattern can be found an exception is thrown. This is to shield you from false security.
                  If tests of more then one subproject are executed, the pattern is applied to each subproject with an exception
                  is thrown if no tests can be found for a particular subproject. In such a case you can use the path notation of the
                  pattern, so that it is applied only to the test task of a specific subproject. Alternatively you can specify the fully
                  qualified task name to be executed. You can also specify multiple patterns. Examples:
                  <itemizedlist>
                      <listitem>
                          <para><literal>gradle -Dtest.single=ThisUniquelyNamedTest test</literal></para>
                      </listitem>
                      <listitem>
                          <para><literal>gradle -Dtest.single=a/b/ test</literal></para>
                      </listitem>
                      <listitem>
                          <para><literal>gradle -DintegTest.single=*IntegrationTest integTest</literal></para>
                      </listitem>
                      <listitem>
                          <para><literal>gradle -Dtest.single=:proj1:test:Customer build</literal></para>
                      </listitem>
                      <listitem>
                          <para><literal>gradle -DintegTest.single=c/d/ :proj1:integTest</literal></para>
                      </listitem>
                  </itemizedlist>
            </para>
            <para>Setting a system property of <literal>taskName.debug</literal> will run the tests in debug mode,
                  suspended and listening on port 5005.  For example:
                  <literal>gradle test -Dtest.single=ThisUniquelyNamedTest -Dtest.debug</literal>                
            </para>
        </section>
Generated at Wed Jun 30 11:22:38 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.