我執行一個簡單的測試,但由於服務豆未能注入測試類測試失敗。下面是我的測試類無法注入服務類Grails的單元測試 - 測試失敗
class QuoteServiceTests extends GrailsUnitTestCase {
def quoteService
void testStaticQuote() {
def staticQuote = quoteService.getStaticQuote()
assertEquals("Messi", staticQuote.author)
assertEquals("Watch me today against Man-City", staticQuote.content)
}
}
我的測試失敗,以下錯誤
Cannot invoke method getStaticQuote() on null object
java.lang.NullPointerException: Cannot invoke method getStaticQuote() on null object
at qotd.QuoteServiceTests.testStaticQuote(QuoteServiceTests.groovy:9)
哪個版本的Grails? – dmahapatro
Grails版本是1.3.5 –