Created
May 22, 2017 20:37
-
-
Save ondrej-kvasnovsky/fd247b9d5b3c8d6c2a44f76ced47c6b0 to your computer and use it in GitHub Desktop.
Test SpringBootApplication in Spock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.rest.app | |
import org.springframework.boot.SpringApplication | |
import org.springframework.boot.autoconfigure.SpringBootApplication | |
import org.springframework.context.annotation.ComponentScan | |
@SpringBootApplication | |
@ComponentScan(["com.rest"]) | |
class RestApp { | |
static void main(String[] args) { | |
SpringApplication.run(RestApp, args) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.rest.app | |
import org.springframework.beans.factory.annotation.Autowired | |
import org.springframework.boot.test.context.SpringBootTest | |
import org.springframework.context.ApplicationContext | |
import spock.lang.Specification | |
@SpringBootTest | |
class RestAppTest extends Specification { | |
@Autowired | |
ApplicationContext applicationContext | |
def "Boots up without error"() { | |
expect: | |
applicationContext | |
} | |
def "App bean is present in application context and app is runnable"() { | |
when: | |
RestApp app = applicationContext.getBean("restApp") | |
app.main([] as String[]) | |
then: | |
noExceptionThrown() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another approach: https://github.com/tomaslin/gs-spring-boot-spock/blob/master/src/test/groovy/hello/HelloControllerSpec.groovy