http://lattes.cnpq.br/0595422027989879; SOUTO, Sabrina de Figueirêdo.
Résumé:
The main purpose of unit tests is to verify the correct work of software and search for defects in the smallest part of the system, in isolated way. However, this isolation not always is possible due to the relationship among the CUT (Class Under Test) and its collaborators, needing the use of mock objects to simulate the collaborators behavior, by a mechanism that the CUT has no science if it is interacting with real collaborators or mock objects. As a result, mock objects can be very useful to write unit tests because they isolate the CUT, improving both efficiency and effectiveness of unit testing. On the other hand, writing tests that use mocks can be a tedious, repetitive, and costly task, even with the support of frameworks, due to the necessary procedures for it working. Given the high importance in the use of mock objects and its benefits, and considering the mentioned drawbacks, we propose a technique that automates the development of tests with mock objects, by automatically generating them for a given testing scenario. This technique is based on automatically identifying interactions among the CUT and its collaborators in a given testing scenario, via both static analysis and dynamic analysis of the code. After these analyses, the technique generates code of test with mock objects for those collaborators and the identified interactions, resulting on a new version of the initial testing scenario code, where the collaborators are replaced by mock objects as well its interactions. Considering the low cost in automatically generate test code with mock objects, it is not necessary maintain this code, which can be generated for each change in the testing scenario. In order to evaluate our technique, we performed a comparative study, by means of experimentation, between the manual and automatic way of
develop tests with mock objects, by observing the spent effort (development time and size
of produced code) on those procedures and the interaction coverage level of the resulting
code, which tries to assure that the generated code contains in minimum the same quality of the input code. The evaluation results demonstrate that our technique was able to reduce the spent effort on developing tests with mock objects, resulting on a better and more precise code when compared to the one manually developed.