Results 1 to 5 of 5

Thread: Generate Unit Tests

  1. #1
    Join Date
    Jan 2005
    Posts
    17

    Default Generate Unit Tests

    Hi,

    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???

    schuer

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    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. #3
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    I don't think generated unit tests are a good idea. This means redundant code that is better generalized in something abstract.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  4. #4
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    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. #5
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    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.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

Similar Threads

  1. Unit Tests for data access layer
    By kuzman in forum Data
    Replies: 16
    Last Post: Oct 25th, 2007, 11:42 AM
  2. MappingLocations for Webapp and Unit tests
    By dserodio in forum Data
    Replies: 1
    Last Post: Oct 23rd, 2005, 01:53 PM
  3. How do you create unit tests for layered applications?
    By paul.barry in forum Architecture
    Replies: 2
    Last Post: May 6th, 2005, 08:31 AM
  4. Unit tests
    By yanis97 in forum Data
    Replies: 2
    Last Post: Jan 9th, 2005, 09:31 PM
  5. Replies: 3
    Last Post: Aug 14th, 2004, 06:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •