Automatic Generation of Accurate Test Templates based on JUnit Asserts

Alessandro Midolo, Emiliano Tramontana · 2023

Software testing is a much needed activity to ensure quality of software systems, and a large and effective test suite has the potential to identify defects. However, substantial effort is required when implementing test cases, due to the knowledge that developers have to acquire on the structure and behaviour of the system under test, and for the time needed to write many test cases to cover most of the execution paths. This paper proposes an automatic approach to generate templates of test cases. A generated test template consists of a JUnit assert, a method call and some default parameters, and can be customised by the developer, since generated code is easy to read. In the proposed approach, some selected industrial software repositories have been analysed to determine the most frequent assert used according to the return type of a method call. Then, such a frequency is used to guide the generation of new test cases for other software systems. The approach has been assessed on real-world Java projects, proving that generated test cases increase application code coverage considerably, while exhibiting readability and effectiveness.

Read the paper · More papers on PaperTik