1 2 3 4 5 6 7 8 9 | The sources /src/trip-planner2/test/integration/HotelStayTests.groovy and /src/trip-planner2/test/unit/HotelStayTests.groovy are containing both a class of the name HotelStayTests. @ line 3, column 1. class HotelStayTests extends GroovyTestCase { ^ 1 error |
1 2 3 4 5 6 7 8 9 10 11 12 13 | class HotelStay { static constraints = { hotel(blank:false) checkIn() checkOut() } String hotel Date checkIn Date checkOut //the rest of the class remains the same } |
1 2 3 4 5 6 7 8 9 | class HotelStayTests extends GroovyTestCase { void testBlankHotel(){ def h = new HotelStay(hotel:"") assertFalse "there should be errors", h.validate() assertTrue "another way to check for errors after you call validate()", h.hasErrors() } //the rest of the tests remain unchanged } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class HotelStayTests extends GroovyTestCase { void testBlankHotel(){ def h = new HotelStay(hotel:"") assertFalse "there should be errors", h.validate() assertTrue "another way to check for errors after you call validate()", h.hasErrors() println "\nErrors:" println h.errors ?: "no errors found" def badField = h.errors.getFieldError('hotel') println "\nBadField:" println badField ?: "hotel wasn't a bad field" assertNotNull "I'm expecting to find an error on the hotel field", badField def code = badField?.codes.find {it == 'hotelStay.hotel.blank'} println "\nCode:" println code ?: "the blank hotel code wasn't found" assertNotNull "the blank hotel field should be the culprit", code } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |