Java – JUnit: Best Practices for developing test cases?
Technology: latest version of JUnit
Some people use hard coded data in test cases, others use attribute files and some XML files As far as I know, XML is better than the other two Is there any better way to use it in industry Please suggest best practices for developing test cases
Solution
It is important that the mapping between the data representation in the test and the data passed to the function under test be as transparent as possible If the data is small and easy to observe in the source code, hard coded data is completely OK The fewer windows you need to keep open in order to understand test cases, the better
XML is best suited for nested tree data, but it is a bit verbose Yaml may also be good for this For flat data, attributes and files with only row organization are OK
No format is superior to others in all respects Choose the simplest and most natural options for a specific test suite / topic area When you need to generate more and more test cases quickly, invest some energy in the most natural format, and then pay again when the survey returns For example, in our project (very large), we have to invent several data representation and write (simple) custom parsers to make it easy to write and read data for test cases