我有一个spring boot 2.0.1应用程序,它使用spock进行集成测试。我有这个:
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中插入一条记录。但是,当我到了