Announcement Announcement Module
No announcement yet.
Generate Unit Tests Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generate Unit Tests


    When you read articles, every time it is said that you have to test your components with unit tests but rarely it is said how.

    I've done some research on internet to find an eventual way to generate unit tests for well known components like DAOs, hibernate beans, some parts of beans (tests on the check of parameters passed to a method), ...

    Unfortunately it seems that it doesn't exist any tool like that.

    For some components, I believe that tests could be generated because it is always the same. Developers would win a lot of time and their code would become much more safe.

    Does any body have heard about something like that???


  • #2
    Unit tests by definition test a single class.

    DAOs typically require other services (databases etc.) to test, and therefore are integration tests.

    There are plugins which will take a class and generate the required unit test methods, but I have never used them.

    I *do* however recommend extensive unit testing It is not uncommon for my code base to have twice as much code in unit tests as I do in "business" code.

    You might also want to lock at mock objects as these are incredibly useful for providing collaborators.


    • #3
      I don't think generated unit tests are a good idea. This means redundant code that is better generalized in something abstract.


      • #4
        Automated unit tests are possible. As was mentioned, some tools already do this. However, I bet they can only test very generic stuff, like null arguments.

        For lean DAOs, Unit tests could probably be totally automated with something like DBUnit. Maybe AppFuse does something like this.

        A while back I was thinking that using Annotations one could indicate what kinds of tests a class should be subjected to. Then a test generator could create the tests or invoke from a pool of test services. The annotation could even be an inline test script using Beanshell or Groovy.

        J. Betancourt


        • #5
          I agree with Costin. An important role of tests is as an executable specification. Generating them will miss this important benefit. I believe that you should always <i>think</i> about your tests; it is no bad thing to have to work to code them.

          Good IDEs allow you to generate test stubs for methods, btw.