【问题标题】:Test Spring startup with spock使用 spock 测试 Spring 启动
【发布时间】:2020-01-09 09:33:35
【问题描述】:

我目前正在尝试测试应用程序以在设置属性时正确启动。 基本上是对配置和自动装配的测试。我不想执行任何 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

有人知道我还能如何通过这个测试吗?

【问题讨论】:

    标签: spring-boot groovy integration-testing spock


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-05-15
      • 1970-01-01
      • 2016-07-16
      • 1970-01-01
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 2017-06-28
      • 2018-08-27
      相关资源
      最近更新 更多