Automated testing คือส่วนสำคัญของ Grails โดยสร้างจาก Groovy Test http://groovy.codehaus.org/Testing+Guide Grails เตรียมวิธีการในการทดสอบระบบไว้มากมายและง่าย ทั้ง - Unit Testing - Integration Testing - Functional Testing สิ่งแรกที่ควรรู้คือ เมื่อใช้คำสั่ง create-* แล้ว Grails จะทำการสร้าง unit test ขึ้นมาให้อัตโนมัติ สามารถดูได้ใน folder /test/unit/ ตัวอย่างการสร้าง controller >grails create-controller simple สิ่งที่จะถูกสร้างขึ้นมาคือ - grails-app/controllers/SimpleController.groovy - test/unit/SimpleControllerTests.groovy ลองทำการทดสอบระบบด้วยคำสั่ง >grails test-app ผลลัพธ์ของการทำงานเป็นดังนี้ ------------------------------------------------------- Running 1 unit test... Running test SimpleControllerTests...PASSED Tests Completed in 5094ms ... ------------------------------------------------------- Tests passed: 1 Tests failed: 0 ------------------------------------------------------- และจะทำการสร้างรายงานของการทดสอบไว้ใน folder test/reports/ เพิ่มเติม ในการใช้คำสั่ง grails test-app สามารถระบุชื่อโดยไม่ต้องต่อท้ายด้วย Tests ได้ดังนี้ >grails test-app SimpleController และได้มากกว่า 1 ตัว >grails test-app SimpleController XXXController |