使用 spock 测试 Spring 启动

Test Spring startup with spock

我目前正在尝试测试应用程序以在设置 属性 时正确启动。 基本上是配置和自动装配的测试。我不想执行任何bean,只想启动系统。

我尝试使用 groovy 2.5.8 和 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()
  }
}

不幸的是,我得到以下编译错误:
Error:(23, 5) Groovyc: Exception conditions are only allowed in 'then' blocks

有人知道我还能通过什么方式完成这个测试吗?

删除 noExceptionThrown 应该会有帮助。 这应该有效:

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