大家好,我正在进行模拟测试,GroovyTestCase的m y类扩展,我正在尝试在void setUp方法中设置一个属性,如中所示:
void setUp()
{
def slurper = new JsonSlurper()
inData = slurper.parse( new File( "src/test/resources/fixtures/v1/watch/20160511_watch_listings_live_in.json" ), 'UTF-8' )
outData = slurper.parse( new File( "src/test/resources/fixtures/v1/watch/20160511_watch_listings_live_out.json" ), 'UTF-8' )
watchPresenter = BinderTestUtils.instanceForLibraryNamed( "dang_v1_watch_presenter" )
watchPresenter.localTranslate = new LocalTranslateHelperTest( )
//def info = [ mapper: mapperMock]
//watchPresenter:[localTranslate:new LocalTranslateHelperTest( )]
println("watchPresenterTranslate:" + watchPresenter.localTranslate.getStrings("en"))
}
但我得到了下一个错误:
无法为类WatchListingPresenterTests设置只读属性:localTranslate。
您知道在这种情况下是否可以设置只读属性吗?
在真实的类中,我使用的localTranslate脚本如下所示:
def strings = this.localTranslate.getStrings( params["lang"] )
我需要模拟这个属性,但我得到了这个错误。
提前谢谢。