Very often in my tests I need to use and modify test data, especially for field validation cases. But I have to be sure next time in next test I’ll get exactly same test data values.

Usually I return just clones of test data objects so if tests even change them it doesn’t affect anyhow the source of test data.

Clone Java object

Clone List in Java

In examples above you can see we converted a Java object/list to JSON and then converted back to Java object/list.

GitHub Gists:

How to clone an object in Java

How to clone lists in Java


You may also find these posts interesting: