我有一个使用spock进行集成测试的spring boot 2.0.1应用程序。我有这个:
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4'
testCompile 'org.spockframework:spock-spring:1.1-groovy-2.4'
我的基本规格:
@ContextConfiguration(loader = SpringBootContextLoader)
@SpringBootTest(classes = MyApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class BaseSpecification extends Specification {
@LocalServerPort
int port;
def setup() {
RestAssured.port = port;
}
}
我的考试
@Transactional
class OfficeControllerTest extends BaseSpecification {
def setup() {
def office = new Office(name: "test)
def hardware = new Hardware(hardwareId: validHardwareId, activationDate: LocalDate.now(), office: office);
assert(hardwareRepository.save(hardware))
List<Hardware> hardwareList = hardwareRepository.findAll();
assert(hardwareList.size() > 0)
}
when:
def response = get("/office/{id}", id)
then:
response.then().log().all()
.statusCode(status)
where:
id | status | api_key
validHardwareId | 200 | validApi
...}
我的测试失败,因为被调用的服务未返回setup()中保留的任何硬件。我已打开跟踪日志记录,但是控制台中没有错误,因此看来我正在将记录插入到H2中。但是,当我到达