Junit: Best practice for developing a test?

Technology: Latest Junit Version Business-Oriented Application

Some people use hard-coded data for a test case, some use property files and some XML files. In my knowledge, xml is better than others. Is there a more efficient approach to use in industry. Please suggest best practice for developing test cases.

+3
source share
3 answers

It is important that the comparison between the presentation of data in the test and the data passed to the function being tested be as transparent as possible. Hard-coded data is fully approved if the data is small and easy to observe right in the source. The fewer windows you need to keep open to understand the test case, the better.

XML is best suited for nested tree data, but that's a bit of verbosity. YAML may also be good for this. For flat data, properties and only string files are fine.

, . / . , , , . , ( ) () , .

+3

, . , , , . , , , , ( , XML - ), . , .

, , - , , .

+2

, . , .

xml: , DOM. - CSV. / .

With JUnit, we are at the unit testing level, we want to know if the public interface is implemented in accordance with the specifications and if they behave in a certain way for all possible input. Therefore, I usually hard-coded test values ​​in testing methods because they usually do not change (there is no need to edit values ​​outside of test classes)

+2
source

Source: https://habr.com/ru/post/1780998/


All Articles