是否定义TestSuite
为:
public class TestSuite {
String name
List<TestCase> testCases = []
}
让你更接近你想要的结果?虽然我自己没有使用过 SnakeYaml ......
编辑
有一些空闲时间,并想出了这个独立的测试脚本:
@Grab( 'org.yaml:snakeyaml:1.10' )
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.representer.Representer
import java.beans.IntrospectionException
import org.yaml.snakeyaml.introspector.Property
public class TestSuite {
String name
List<TestCase> testCases = []
}
class TestCase {
String name
String id
}
class NonMetaClassRepresenter extends Representer {
protected Set<Property> getProperties( Class<? extends Object> type ) throws IntrospectionException {
super.getProperties( type ).findAll { it.name != 'metaClass' }
}
}
TestSuite suite = new TestSuite( name:'Carrier Handling and Traffic' )
suite.testCases << new TestCase( name:'Call setup by UE', id:'DCM00000001' )
println new Yaml( new NonMetaClassRepresenter() ).dumpAsMap( suite )
哪个打印:
name: Carrier Handling and Traffic
testCases:
- id: DCM00000001
name: Call setup by UE