我有以下 Controller :
class MyController {
def simple = {
render "simple"
}
}
分别是以下测试用例:
class MyControllerTests extends ControllerUnitTestCase {
void testSimple() {
controller.simple
def body = controller.response.contentAsString
assertEquals "simple", body
}
}
我本来希望该测试能够成功通过。令人惊讶的是,它失败并显示以下结果:
junit.framework.ComparisonFailure: null expected:<[simple]> but was:<[]>
我已经通过浏览器运行了该应用程序,并且可以按预期工作(即打印“简单”)。
我在这里想念什么?
最佳答案
嗨,我认为您的测试应如下所示:
void testSimple() {
controller.simple()
def body = controller.response.contentAsString
assertEquals "simple", body
}
您需要调用简单的 Action (关闭)。
看到这里更多:http://www.gitshah.com/2010/04/unit-testing-grails-controller-part-1.html
谢谢,
吉姆
关于unit-testing - 在Grails中使用ControllerUnitTestCase进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7158150/