Skip to content

Instantly share code, notes, and snippets.

@ondrej-kvasnovsky
Created May 22, 2017 20:37
Show Gist options
  • Save ondrej-kvasnovsky/fd247b9d5b3c8d6c2a44f76ced47c6b0 to your computer and use it in GitHub Desktop.
Save ondrej-kvasnovsky/fd247b9d5b3c8d6c2a44f76ced47c6b0 to your computer and use it in GitHub Desktop.
Test SpringBootApplication in Spock
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)
}
}
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