Thursday, October 3, 2013

Generate YAML for testing

Hi folks, Among several other ways, it's easy enough to generate your own YAML for testdata using YAMLWriter.

 https://code.google.com/p/yamlbeans/

Here's a quick example:
....
import com.esotericsoftware.yamlbeans.YamlWriter;
public class GenYaml {
public static void main(String args[]) throws IOException
{
ArrayList<MyModel> l = new ArrayList<MyModel>();
YamlWriter writer = new YamlWriter(new FileWriter("MyModel-test.yml"));
for(int i=0; i < 20; i++)
{
MyModel t = new MyModel(
add,
whatever,
data,
you,
need
);
l.add(t);
}
writer.write(l);
writer.close();
}
}
view raw gistfile1.java hosted with ❤ by GitHub

I did find that I had to modify the output a tad (adding bangs here or there), but for the most part... it's pretty good.

No comments:

Post a Comment