【发布时间】:2015-03-06 14:14:59
【问题描述】:
我在 GGTS 中运行 grails 2.3.3。
我正在为 Spring GGTS 中的服务功能成功运行单个单元测试。
我希望能够使用这个单元测试来开发特定的功能 - 这种方法将真正加快我的开发速度。
这意味着我需要对正在测试的服务功能进行更改,然后一遍又一遍地重新测试(无疑是对我的编码技能的悲哀反思!)。问题是当我对逻辑或任何 log.debug 输出进行更改时,它在测试中没有通过。换句话说,测试继续针对原始服务功能而不是更新的服务功能运行。
为了让我强制它使用更新的功能,我发现这样做的唯一方法是重新启动 GGTS!
我可以在 GGTS 中使用一个命令来强制对我正在测试的函数的最新版本进行测试吗?
以下是我在 GTTS 中使用的命令:
测试应用单元:UtilsService
我确实在功能更新后运行了一次清理但没有任何成功:
测试应用-clean
我还在努力从测试函数中获取额外的输出 - 引入“println”或“log.debug”命令会导致测试失败。
了解有关测试语法的文档的良好链接会很有用 - 我已经查看了 grails 第 12 节关于一般测试的内容。
这里是测试文件:
package homevu1
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
*/
@TestFor(UtilsService)
class UtilsServiceSpec extends Specification {
// to test utilSumTimes for example use the command :
// test-app utilSumTimes
// test-app HotelStay
def setup() {
}
def cleanup() {
}
void "test something"() {
when:
def currSec = service.utilSumTimeSecs( 27, 1, false)
//println "currSec" , currSec
then:
//println "currSec" , currSec
assert currSec == "26"
}
}
如果我取消注释任何一个 println 行,这些 cmets 不会显示并且测试失败。
欢迎任何建议。
-麦克
【问题讨论】:
标签: spring unit-testing grails