【发布时间】:2010-02-18 20:17:43
【问题描述】:
这几乎是从 IBM 的 Mastering Grails 系列中逐字记录的。
DateTagLib.groovy:
class DateTagLib {
def thisYear = {
out << Calendar.getInstance().get(Calendar.YEAR)
}
}
DateTagLibTests.groovy:
class DateTagLibTests extends TagLibUnitTestCase {
def dateTagLib
protected void setUp() {
super.setUp()
dateTagLib = new DateTagLib()
}
void testThisYear() {
String expected = Calendar.getInstance().get(Calendar.YEAR)
assertEquals("years do NOT match", expected, dateTagLib.thisYear())
}
protected void tearDown() {
super.tearDown()
}
}
grails test-app DateTagLib 输出:
-------------------------------------------------------
Running 1 unit test...
Running test DateTagLibTests...
testThisYear...FAILED
Tests Completed in 359ms ...
-------------------------------------------------------
Tests passed: 0
Tests failed: 1
-------------------------------------------------------
我尝试匹配类型(int/long/String),但我仍然在用头撞墙。
这个测试也失败了:
void testThisYear() {
long expected = Calendar.getInstance().get(Calendar.YEAR)
assertEquals("years do NOT match", expected, (long) dateTagLib.thisYear())
}
【问题讨论】:
标签: java grails groovy junit taglib