Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Grails 3 integration test in IntelliJ IDEA

I'm not able to run an integration test in IntelliJ IDEA. Here is a test template generated by grails create-integration-test

@Integration
@Rollback
class TestServiceIntSpec extends Specification{
 void "test something"() {
   //some code here
 }
}

Here is the output when I'm trying to run it from junit configuration :

Process finished with exit code 0
Empty test suite.

Also seems like grails using development env if I'm running this test from IDE, I have to specify env explicitly via -Dgrails.env=test

like image 928
enzo Avatar asked Jan 18 '26 11:01

enzo


2 Answers

Spock tests ('Specification') identify which methods are tests by the presence of when:, then:, or expect:, etc.

like image 195
HypeMK Avatar answered Jan 21 '26 01:01

HypeMK


HypeMK's answer is correct. To elaborate, the following test may not run because it does not have the presence of the spock keywords that outline the specification nature of the test (expect, when, then, etc):

@TestFor(BeanFormTagLib)
class BeanFormTagLibSpec extends Specification {
    def setup() {}

    void "address setup"() {
        assertOutputEquals ('Hello World', '<g:beanFormTagLib domainName="com.myapp.Address" />');
    }
}

Here we correct the issue by adding the "expect" keyword:

@TestFor(BeanFormTagLib)
class BeanFormTagLibSpec extends Specification {
    def setup() {}
    void "address setup"() {
        expect:
        assertOutputEquals ('Hello World', '<g:beanFormTagLib domainName="com.myapp.Address" />');
    }
}
like image 22
IcedDante Avatar answered Jan 21 '26 02:01

IcedDante



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!