Good practice to pass data to test cases with POJOs?

Hey,

currently I’m struggling with passing data to my test modules (Test Cases). We have a lot of variables that have further nested variables. Similar like this one:

{
"name": "Max",
"value": 532,
"tables": [
	{
		"name": "Table1",
		"rows": [
			{
				"a": 1,
				"b": 2,
				"c": "3"
			},
			{
			...
			}
		]
	},
	{
	...
	}
]
}

Now I want to pass all of this informations to the modules and I don’t really think that a map is a good idea, because you always have to take a look how the keys are called and you would have maps in maps.

One of my solutions would be creating POJOs as “Keywords”. It is also possible to add static methods for generating objects with default or random data and there are propsals in the editor for the defined variables.

Has anyone had any experience with this? Is it a good idea or is there something better?

I hope you can help me.
Kind regards

I do so quite often. “Keywords” is just a directory name. You can safely locate any types of Groovy classes there. You should regard it as a synonym to the “src/main/groovy” directory of a usual Maven/Groovy project.

I think that creating POJOs as Data Transfer Object and transferring them between test cases is the best approach that allows you most flexibility and robustness. If you have already made it, you should stick to it.


By the way you wrote this:

{
"name": "Max",
"value": 532,
"tables": [
	{
		"name": "Table1",
		"rows": [
			{
				"a": 1,
				"b": 2,
				"c": "3"
			},

This example implies that you possibly have your data serialised as a JSON text. Am I right? In that case, you can easily read that *.json file by groovy.json.JsonSlurper, and consume the data inside it. Read the following tutorial for how to

Hello @ kazurayam,

I will then focus on implementing these DTOs.

Thank you for your help