How to run a single test class?

(Esen Sagynov) #1

I am running hibernate test now and need to test specific tests only instead of waiting for several hour to see the full results. I run the following command:

gradlew clean :hibernate-core:matrix_cubrid -Dtest.single=:hibernate-core:test:org/hibernate/test/annotations/EntityTest

Here gradlew is a hibernate wrapper for gradle.

But I can’t get it work. The command still runs the entire suite instead of a single one that I’ve defined.

How can I run a single test suite?


(Peter Niederwieser) #2

Sounds like the ‘Test’ task that executes ‘EntityTest’ isn’t named ‘test’. For example, if the task is named ‘integrationTest’, you’ll have to use ‘-DintegrationTest.single=…’.

(Esen Sagynov) #3

I just tried this:

gradlew clean -Dhibernate-core:matrix_cubrid.single=EntityTest :hibernate-core:matrix_cubrid

Still doesn’t work. Still executes all tests.

(Peter Niederwieser) #4

If at all, the task name is ‘matrix_cubrid’. I can’t tell if this is a ‘Test’ task though.

(Esen Sagynov) #5

I can’t make it work at all. Tried everything:

gradlew clean -Dmatrix_cubrid.single=EntityTest matrix_cubrid
  gradlew -Dmatrix_cubrid.single=org/hibernate/test/annotations/EntityTest matrix_cubrid
  gradlew -Dmatrix_cubrid.single=:hibernate-core:test:org/hibernate/test/annotations/EntityTest matrix_cubrid
  gradlew -Dmatrix_cubrid.single=:hibernate-core:org/hibernate/test/annotations/EntityTest matrix_cubrid
  gradlew -Dmatrix_cubrid.single=:hibernate-core:test:EntityTest matrix_cubrid

Nothing works. All either execute all test all say “Could not find matching test for pattern”.

What else can I try?

(Esen Sagynov) #6

Finally found:

./gradlew clean -Dmatrix_cubrid.single=annotations/EntityTest :hibernate-core:matrix_cubrid

(Peter Niederwieser) #7

The first line should work as long as you run just the ‘matrix_cubrid’ task that contains the test (I assume there might be multiple such tasks). The other lines have incorrect test name patterns. As usual, the Gradle User Guide has the details.

By the way, ‘gradlew’ is the Gradle Wrapper.

(Esen Sagynov) #8

Yes, I understood that from the docs. :slight_smile:

(gradlegoodness) #9


I have been struggling getting this working in the hibernate project. The test case I created in the hibernate-core subproject is this object.


The successful execution of this single test works using

$ gradlew -Dtest.single=CompositeKeyDeleteTest :hibernate-core:test

(Gaurav Jha) #10

If the test class structure is as follows: test-service/src/test/java/sample/tools/source/

can this single test be executed as : gradlew -Dtest.single=annotations/TestServiceSample :test-service:test

The gradle task is defined as “test” only.