Integrationstest mit Spring Boot und Spock
Was ist der beste Weg, um einen Integrationstest durchzuführen (z. B.@IntegrationTest
) mit Spock? Ich möchte die gesamte Spring Boot-Anwendung booten und einige HTTP-Aufrufe ausführen, um die gesamte Funktionalität zu testen.
Ich kann es mit JUnit machen (zuerst läuft die App und dann werden die Tests ausgeführt):
@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
}
}
Aber mit Spock startet die Anwendung nicht:
@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
}
}
Für Spock habe ich natürlich die richtigen Abhängigkeiten in meiner Gradle-Build-Datei angegeben:
...
dependencies {
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'org.spockframework:spock-spring:0.7-groovy-2.0'
}
...
Vermisse ich etwas?