Search code examples
spring-bootgroovyintegration-testingspock

Test Spring startup with spock


I am currently trying to test the application to start up correctly when a property is set. Basically a test of the configuration and autowiring. I do NOT want to execute any bean, just want to start up the system.

My attempt with groovy 2.5.8 and spock 1.3-groovy2.5:

@ActiveProfiles([MY_PROFILES])
@WebAppConfiguration
@ContextConfiguration
@SpringBootTest(classes = [Application], properties = ["property.enabled=true"])
class IntegrationTest extends Specification {

  def "Service starts up with property enabled"() {
    expect:
    noExceptionThrown()
  }
}

Unfortunately I get the following compile error:
Error:(23, 5) Groovyc: Exception conditions are only allowed in 'then' blocks

Does anybody have an idea how else I can achieve this test?


Solution

  • Removing noExceptionThrown should help. This should work:

      def "Service starts up with property enabled"() {
        expect: "All beans are created"
      }