neel
neel

Reputation: 391

How to run integration test for a particular class in grails 3.0

I am new to grails, and am trying to run already existing integration tests for a particular class (using grails 3.0.11).(I don't want to run ALL the test classes, just a single one)

  1. Is it possible to do that for integration tests or can only Unit tests be run in that way?
  2. If yes, then can somebody suggest how it can be done?

The test class looks like this

@TestFor(ClassToBeTested)  
@Mock([])  
class ClassToBeTestedSpec extends Specification {  
...  
}  

I have tried the following after looking through posts here,

$ grails test-app -integration ClassToBeTested    

But I get below error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':integrationTest'.
> No tests found for given includes: [ClassToBeTested]

Thanks.

Upvotes: 4

Views: 1211

Answers (3)

nbkhope
nbkhope

Reputation: 7474

In Grails 3, you can run a specific test like this:

grails test-app com.yourpackage.yourapp.SomeWhateverSpec

or use star if you don't want to write the package hierarchy:

grails test-app *.SomeWhateverSpec

Don't forget to add the Spec word at the end, otherwise it won't work.

Upvotes: 1

Mike Houston
Mike Houston

Reputation: 264

I had to add 'Tests' to the end of the argument to make this work with JUnit. Perhaps Spock requires the text 'Spec' on the end too?

With JUnit, I needed to enter a pattern that matches the actual test class, including 'Tests':

--tests *ClassToBeTestedTests

I am guessing that using Spock, it might be something like (I don't have any Spock tests to verify this on):

--tests *.ClassToBeTestedSpec

Upvotes: 2

HypeMK
HypeMK

Reputation: 351

For a test class in a non-default package:

grails test-app -integration *.ClassToBeTested

Or with gradle:

--tests *.ClassToBeTested

Upvotes: 2

Related Questions