我已经开发了在Java在过去,现在我想学习杯/常规的使用 这有点过教程.

import grails.test.*

class DateTagLibTests extends TagLibUnitTestCase {

    def dateTagLib

    protected void setUp() {
        super.setUp()
        dateTagLib = new DateTagLib()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testThisYear() {
        String expected = Calendar.getInstance().get(Calendar.YEAR) 

        // NOTE: This statement fails
        assertEquals("the years dont match and I dont know why.", expected, dateTagLib.thisYear())

    }
}

DateTagLibTests.时髦的
(注: 这TagLibUnitTestCase是为多种解决方案1.2.1并未使用的版本中的 教程)

由于某种原因上述的测试失败:

预期:<2010>但是:<2010>

我已试图更换的测试上述与下列备选版本的测试和测试通过只是罚款:

void testThisYear() {
    String expected = Calendar.getInstance().get(Calendar.YEAR)
    String actual = dateTagLib.thisYear()

    // NOTE: The following two assertions work:
    assertEquals("the years don\'t match", expected, actual)
    assertTrue("the years don\'t match", expected.equals(actual))
}

这两个版本的测试基本上是相同的事情吗?

除非有新的东西在杯1.2.1或时髦,我不理解。他们应该是同一类型,因为价值都值 日历。getInstance().获得(日历。年)

有帮助吗?

解决方案

对返回的自dateTagLib.今年成()必须不一串。

尝试

  assertEquals("the years dont match and I dont know why.", expected, dateTagLib.thisYear().toString())

在你工作的例子,是时髦的转换。今年成()to a String你。

打印出dateTagLib.今年成().类是肯定的。

欢呼

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top