gpt4 book ai didi

grails - 使用use(TimeCategory)时,使用Spock进行单元测试失败

转载 作者:行者123 更新时间:2023-12-02 14:50:32 27 4
gpt4 key购买 nike

我在项目中使用Grails 2.4.4,并且尝试使用Spock编写单元测试用例。我尝试进行单元测试的方法使用use(TimeCategory)。测试用例运行时间过长,在调试时,我发现它并没有超出我拥有use(TimeCategory)的代码点。请在下面找到我编写的方法和测试用例:

def getEstimatedSl(val) {

// some code
calculateSl()
// some code
}

def calculateSl() {
use(TimeCategory) {
interval = 10
startDate = //some date value//
endDate = //some date value//
}

while (endDate.compareTo(startDate) >= 0) {
use(TimeCategory) {
startDate += interval
}
}
}

void "test getEstimatedSl success"() {
when:
def dto = service.getEstimatedSl('ABCDEFGH')

then:
dto.slots == /*dto value that I get*/
dto.count == 4
}

有人可以告诉我我在做什么错吗?提前致谢。

最佳答案

抱歉,我迟迟未发布我的答案,但事实证明我的服务代码没有错。我没有在测试用例中设置间隔(第10行),因此我的时间处于无限循环中。
谢谢大家的帮助!

关于grails - 使用use(TimeCategory)时,使用Spock进行单元测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31979981/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com