GenUTest: a unit test and mock aspect generation tool

  • Benny Pasternak
  • Shmuel Tyszberowicz
  • Amiram Yehudai
Regular Paper


Unit testing plays a major role in the software development process. What started as an ad hoc approach is becoming a common practice among developers. It enables the immediate detection of bugs introduced into a unit whenever code changes occur. Hence, unit tests provide a safety net of regression tests and validation tests which encourage developers to refactor existing code with greater confidence. One of the major corner stones of the agile development approach is unit testing. Agile methods require all software classes to have unit tests that can be executed by an automated unit-testing framework. However, not all software systems have unit tests. When changes to such software are needed, writing unit tests from scratch, which is hard and tedious, might not be cost effective. In this paper we propose a technique which automatically generates unit tests for software that does not have such tests. We have implemented GenUTest, a prototype tool which captures and logs interobject interactions occurring during the execution of Java programs, using the aspect-oriented language AspectJ. These interactions are used to generate JUnit tests. They also serve in generating mock aspects—mock object-like entities, which enable testing units in isolation. The generated JUnit tests and mock aspects are independent of the tool, and can be used by developers to perform unit tests on the software. Comprehensiveness of the unit tests depends on the software execution. We applied GenUTest to several open source projects such as NanoXML and JODE. We present the results, explain the limitations of the tool, and point out direction to future work to improve the code coverage provided by GenUTest and its scalability.


Time Stamp Unit Test Code Coverage Automate Software Engineer Capture Phase 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. 1.
    Andrews, J.H., Haldar, S., Lei, Y., Li, F.C.H.: Tool support for randomized unit testing. In: Proceedings of the 1st International Workshop on Random Testing, pp. 36–45 (2006)Google Scholar
  2. 2.
    Arrays (Java 2 Platform SE 5.0).: Accessed Jan 2009
  3. 3.
    AspectJ.: Accessed Jan 2009
  4. 4.
    Beckert, B., Hähnle, R., Schmitt, P.H. (eds.): Verification of Object-Oriented Software: The KeY Approach. Lecture Notes in Computer Science, vol. 4334. Springer, Berlin (2007)Google Scholar
  5. 5.
    Boshernitsan, M., Doong, R., Savoia, A.: From Daikon to Agitator: lessons and challenges in building a commercial tool for developer testing. In: Proceedings of the International Symposium on Software Testing and Analysis, pp. 169–180 (2006)Google Scholar
  6. 6.
    Clifton, M.: Advanced Unit Test, Part V—Unit Test Patterns, January 2004. Accessed Jan 2009
  7. 7.
    Commons Lang.: Accessed Jan 2009
  8. 8.
    Csallner C., Smaragdakis Y.: JCrasher: an automatic robustness tester for Java. Softw. Pract. Experience 34(11), 1025–1050 (2004)CrossRefGoogle Scholar
  9. 9.
    d’Amorim, M., Pacheco, C., Xie, T., Marinov, D., Ernst, M.: An empirical comparison of automated generation and classification techniques for object-oriented unit testing. In: Proceedings of the 21st IEEE/ACM International Conference on Automated Software Engineering (ASE 2006), pp. 59–68 (2006)Google Scholar
  10. 10.
    Easy Mock.: Accessed Jan 2009
  11. 11.
    EclEmma.: Accessed Jan 2009
  12. 12.
    Eclipse.: Accessed Jan 2009
  13. 13.
    Elbaum, S., Chin, H.N., Dwyer, M.B., Dokulil, J.: Carving differential unit test cases from system test cases. In: Proceedings of the 14th ACM SIGSOFT International Symposium on Foundations of Software Engineering, pp. 253–264 (2006)Google Scholar
  14. 14.
    Extreme Programming.: Visited January (2009)
  15. 15.
    Fowler M.: Refactoring: Improving the Design of Existing Code. Addison-Wesley, Reading (2000)Google Scholar
  16. 16.
    Gamma E., Helm R., Johnson R., Vlissides J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading (1995)Google Scholar
  17. 17.
    Husted T., Massol V.: JUnit in Action. Manning Publications, Greenwich (2003)Google Scholar
  18. 18.
    HP WinRunner software.: Accessed Jan 2009
  19. 19.
    IdentityHashMap (Java 2 Platform SE 5.0).: Accessed Jan 2009
  20. 20.
    Intel VTune Performance Analyzer.: Accessed Jan 2009
  21. 21.
    Java programming dynamics, Part 2: Introducing reflection.: Accessed Jan 2009
  22. 22.
    JODE (Java Optimize and Decompile Environment).: Accessed Jan 2009
  23. 23.
    JUnit.: Accessed Jan 2009
  24. 24.
    Kiczales, G., Lamping, J., Mendhekar, A., Maeda, C., Lopes, C., Loingtier, J.M., Irwin, J.: Aspect-oriented programming. In: Proceedings of the 11th European Conference on Object-Oriented Programming (ECOOP), Jyväskylä, Finland (1997)Google Scholar
  25. 25.
    Laddad R.: AspectJ in Action: Practical Aspect-Oriented Programming. Manning Publications, Greenwich (2003)Google Scholar
  26. 26.
    Mackinnon, T., Freeman, S., Craig, P.: Endo-testing: unit testing with mock objects. In: Extreme Programming Examined, pp. 287–301. Addison-Wesley, Reading (2001)Google Scholar
  27. 27.
    Monk, S., Hall, S.: Virtual Mock Objects using AspectJ with JUnit, 2002. Accessed January 2009
  28. 28.
    NanoXML.: Accessed Jan 2009
  29. 29.
    Oriat, C.: Jartege: a tool for random generation of unit tests for Java classes. In: Proceedings of the Second International Workshop on Software Quality (SOQUA), pp. 242–256 (2005)Google Scholar
  30. 30.
    Orso, A., Kennedy, B.: Selective capture and replay of program executions. In: Proceedings of the Workshop on Dynamic Analysis, pp. 1–7 (2005)Google Scholar
  31. 31.
    Pacheco, C., Ernst, M.: Eclat: automatic generation and classification of test inputs. In: Proceedings of the 19th European Conference on Object-Oriented Programming (ECOOP), Glasgow, Scotland, pp. 504–527(2005)Google Scholar
  32. 32.
    Pasternak, B., Tyszberowicz, S., Yehudai, A.: GenUTest: a unit test and mock aspect generation tool. In: Proceedings of Haifa Verification Conference, Lecture Notes in Computer Science, vol. 4899, pp. 252–266. Springer, Berlin (2007)Google Scholar
  33. 33.
    Saff, D., Artzi, S., Perkins, J., Ernst, M.: Automated test factoring for Java. In: Conference of Automated Software Engineering (ASE), pp. 114–123 (2005)Google Scholar
  34. 34.
    Steven, J., Chandra, P., Fleck, B., Podgurski, A.: jRapture: a Capture/Replay tool for observation-based testing. In: Proceedings of the International Symposium on Software Testing and Analysis, pp. 158–167 (2000)Google Scholar
  35. 35.
    String (Java 2 Platform SE 5.0).: Accessed Jan 2009
  36. 36.
    The Daikon invariant detector.: Accessed Jan 2009
  37. 37.
    van Vliet H.: Software Engineering: Principles and Practice. 2nd edn. Wiley, New York (2000)Google Scholar
  38. 38.
    Visser, W., Pǎsǎreanu, C.S., Khurshid, S.: Test input generation with Java PathFinder. In: Proceedings of the ACM SIGSOFT International Symposium on Software Testing and Analysis, pp. 97–107 (2004)Google Scholar
  39. 39.
    Xie, T., Marinov, D., Notkin, D.: Rostra: A framework for detecting redundant object-oriented unit tests. In: Proceedings of the 19th IEEE International Conference on Automated Software Engineering (ASE), pp. 196–205 (2004)Google Scholar
  40. 40.
    Xie, T., Marinov, D., Schulte, W., Notkin, D.: Symstra: A framework for generating object-oriented unit tests using symbolic execution. In: Proceedings of the International Conference on Tools and Algorithms for the Construction and Analysis of Systems (TACAS) (2005)Google Scholar
  41. 41.
    XStream 1.2.2.: Accessed Jan 2009
  42. 42.
    Yuan, H., Xie, T.: Substra: a framework for automatic generation of integration tests. In: Proceedings of the International Workshop on Automation of Software Test, pp. 64–70 (2006)Google Scholar

Copyright information

© Springer-Verlag 2009

Authors and Affiliations

  • Benny Pasternak
    • 1
  • Shmuel Tyszberowicz
    • 2
  • Amiram Yehudai
    • 1
  1. 1.Tel-Aviv UniversityTel AvivIsrael
  2. 2.The Academic College Tel-Aviv YaffoTel AvivIsrael

Personalised recommendations