私はそれを動かすことができませんでした。メソッドがモックされていないようです。
静的Javaメソッドをモックするのに適した代替のGroovyテストフレームワークはありますか?
2011年3月2日更新:コードの追加:
私は実際にScalaXML.loadXml(ユニットテストのためにGroovyを試しています)クラスをモックしようとしています:
これは私のテストケースです:
// ContentManagementGatewayTest.groovy
class ContentManagementGatewayTest extends GMockTestCase
{
void testGetFileList()
{
// Preparing mocks code will go here, see below
play {
GetFileGateway gateway = new GetFileGateway();
gateway.getData();
}
}
}
// GetFileGateway.scala
class GetFileGateway {
def getData()
{
// ...
val xmlData = XML.loadData("file1.txt");
}
}
gmockとmetaClassの両方を使用してテストしてみました。
// metaClass:
XML.metaClass.'static'.loadFile = {file ->
return "test"
}
// gmock:
def xmlMock = mock(XML)
xmlMock.static.loadFile().returns(stream.getText())