什么是使用Spock运行集成测试(例如,
在这个工作中的JUnit测试中启动Spring Boot应用程序(首先启动应用程序,然后执行测试)。
但是使用Spock时应用程序无法启动(我该如何使其启动?):
当然,对于Spock,我在我的Gradle构建文件中指定了正确的依赖项。
@IntegrationTest
)的最佳方法?我想要引导整个Spring Boot应用程序并执行一些HTTP调用来测试整个功能。在这个工作中的JUnit测试中启动Spring Boot应用程序(首先启动应用程序,然后执行测试)。
@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
}
}
但是使用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
}
}
当然,对于Spock,我在我的Gradle构建文件中指定了正确的依赖项。
...
dependencies {
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'org.spockframework:spock-spring:0.7-groovy-2.0'
}
...