2

私は次のようなドメインクラスを持っています

package trip.side
import java.text.SimpleDateFormat

class HotelStay {
    String hotel
    Date checkIn
    Date checkOut

    static constraints = {
    }
    String toString(){
     def sdf = new SimpleDateFormat("EEEE")
    "${hotel}(${sdf.format(checkIn)} to ${sdf.format(checkOut)})"
    }

}

そしてHotelStayTests内にテストケースtoStringメソッドを書きました

void testToString() {
      def h = new HotelStay(hotel:"Hilton")
      def df = new SimpleDateFormat("MM/dd/yyyy")
      h.checkIn = df.parse("10/1/2008")
      h.checkOut = df.parse("10/5/2008")
      println h
      assertToString h, "Hilton (Wednesday to Sunday)"
    }

HotelStayTests クラスを完了する

package trip.side



import grails.test.mixin.*
import org.junit.*
import java.text.SimpleDateFormat

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(HotelStay)
class HotelStayTests {

   void testSomething() {
   // Simple test by creating new object and asserting it
          // fail "Implement me"
        HotelStay hs = new HotelStay(hotel:"Ibis")
        assertEquals "Ibis", hs.hotel
    }   

    void testToString() {
      def h = new HotelStay(hotel:"Hilton")
      def df = new SimpleDateFormat("MM/dd/yyyy")
      h.checkIn = df.parse("10/1/2008")
      h.checkOut = df.parse("10/5/2008")
      println h
      assertToString h, "Hilton (Wednesday to Sunday)"
    }
}

しかし、これは失敗し、エラーレポートを提供します

No signature of method: trip.side.HotelStayTests.assertToString() is applicable for argument types: (trip.side.HotelStay, java.lang.String) values: [Hilton(Wednesday to Sunday), Hilton (Wednesday to Sunday)] Possible solutions: testToString()
groovy.lang.MissingMethodException: No signature of method: trip.side.HotelStayTests.assertToString() is applicable for argument types: (trip.side.HotelStay, java.lang.String) values: [Hilton(Wednesday to Sunday), Hilton (Wednesday to Sunday)]
Possible solutions: testToString()
    at trip.side.HotelStayTests.testToString(HotelStayTests.groovy:28)
System output
Hilton(Wednesday to Sunday)

ここで何がうまくいかないのですか?

4

1 に答える 1

3

assertToStringGroovyTestCase クラスの一部です。

テストクラスはextend GroovyTestCaseこの機能を得る必要があります

于 2012-06-20T12:43:03.643 に答える