相关疑难解决方法(0)

使用Spring Boot和Spock进行集成测试

@IntegrationTest使用Spock 运行集成测试(例如)的最佳方法是什么?我想引导整个Spring Boot应用程序并执行一些HTTP调用来测试整个功能.

我可以使用JUnit(首先运行app然后执行测试):

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = MyServer.class)
@WebAppConfiguration
@IntegrationTest
class MyTest {
   RestTemplate template = new TestRestTemplate();

   @Test
   public void testDataRoutingWebSocketToHttp() {
      def a = template.getForEntity("http://localhost:8080", String.class)
      println a
   }
}
Run Code Online (Sandbox Code Playgroud)

但是使用Spock,应用程序无法启动:

@SpringApplicationConfiguration(classes = MyServer.class)
@WebAppConfiguration
@IntegrationTest
class MyTestSpec extends Specification {

   RestTemplate template = new TestRestTemplate();

   def "Do my test"() {
      setup:
      def a = template.getForEntity("http://localhost:8080", String.class)

      expect:
      println a
   }
}
Run Code Online (Sandbox Code Playgroud)

当然,对于Spock,我在Gradle构建文件中指定了正确的依赖项:

...
dependencies {
   testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
   testCompile 'org.spockframework:spock-spring:0.7-groovy-2.0'
}
...
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

java groovy gradle spock spring-boot

36
推荐指数
3
解决办法
3万
查看次数

标签 统计

gradle ×1

groovy ×1

java ×1

spock ×1

spring-boot ×1