我想在我的Grails應用程序中編寫一些服務的單元測試。服務'MyService'使用位於$ APP-ROOT/src/groovy /被稱爲'MyHelperClass'的類。如何在Grails中的'src'文件夾中模擬類(單元測試)
在用於爲MyService單元測試,我試圖創建MyHelperClass一個模擬像這樣:
def myHelperClassMock = mockFor(MyHelperClass)
def myService = new MyService()
myService.myHelperClass = myHelperClassMock.createMock()
這給了錯誤:
Error casting map to com.mycompany.myproject.MyHelperClass, Reason: Could not find matching constructor for: com.mycompany.myproject.MyHelperClass()
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Error casting map to com.mycompany.myproject.MyHelperClass, Reason: Could not find matching constructor for: com.mycompany.myproject.MyHelperClass()
at grails.test.GrailsMock.createMock(GrailsMock.groovy:91)
at grails.test.GrailsMock$createMock.call(Unknown Source)
at com.mycompany.myproject.MyServiceTests.testSomething(MyServiceTests.groovy:17)
這似乎只在SRC類的情況發生/,並且對於grails-app/services中的類似乎工作正常。任何想法如何讓它看到src /中的類?
謝謝!