Re: Unit testing

From: Chuck Hill (chil..lobal-village.net)
Date: Mon Apr 10 2006 - 12:47:20 EDT

  • Next message: Anders Peterson: "Build from source"

    I think that Fabian is making a very important point here: All
    automated tests are not unit tests. Unit tests are intended to test
    the smallest possible unit of code in isolation (or as close to
    isolation as can reasonable be achieved). There is an interesting /
    provocative article in this topic here: http://www.javaranch.com/
    journal/200603/Journal200603.jsp#a1

    "They fell into the popular trap of thinking that because they run
    the tests with JUnit, they must be unit tests."

    "Unit Test: The smallest amount of testable code. Often a single
    method/function, sans the use of other methods or classes. Fast!
    Thousands of unit tests can run in ten seconds or less! A unit test
    NEVER uses:
    a database
    an app server (or server of any kind)
    file/network I/O or file system;
    another application;
    the console (System.out, System.err, etc.)
    logging
    most other classes (exceptions include DTO's, String, Integer, mocks
    and maybe a few others)."

    I find his definition of Unit Test a little restrictive for
    WebObjects. My "unit tests" often involve EOF. In any case, it is
    worth reading and thinking about.

    What I strive for are very simple UI (WOComponent) sub-classes so
    that the UI does not need unit testing. For example, to implement an
    action method to perform a search I would use a method like this on
    my component / page:

    public NSArray searchResults() {
         return Customer.customersNamed(editingContext(), searchString);
    }

    Customer.customersNamed() _does_ get test. But searchResults() is so
    simple that it could not possibly break (IMHO) and hence does not
    need or benefit from testing.

    Of course, there could still be a bug if the search criteria in the
    UI is not bound to searchString. But that falls under the heading of
    functional test (in my mind) and, as Fabian, points out there are
    better tools for that sort of testing.

    Chuck

    On Apr 9, 2006, at 9:17 AM, Fabian Peters wrote:

    > Hi Miguel,
    >
    > Am 09.04.2006 um 13:49 schrieb Miguel Arroz:
    >
    >> Hi!
    >>
    >> Not yet, I'm just starting (a late start, I know, but better
    >> latter then never!).
    >>
    >> I could make WOUnitTest work (it's really easy) but as far as I
    >> understand, it only tests the EO part of my app. I'm also aware of
    >> DBUnit, but I think that's too much complex for what I want to do.
    >>
    >> About the RR loop, I still have absolutely no ideia how to do it
    >> (special because I'm using a lot of ajax cals). Any ideas? I guess
    >> WOUnit would do that, but it's not available for download.
    >
    > I can't see how you would use WOUnitTest to test AJAX calls? I use
    > webtest (<http://webtest-community.canoo.com/>) for functional
    > testing. It's based on HtmlUnit, which delivers pretty strong JS
    > support, too. That's something quite different from unit testing,
    > however...
    >
    >> Yours
    >>
    >> Miguel Arroz
    >
    > cheers
    >
    > Fabian
    >
    >> On 2006/04/09, at 02:37, Chuck Hill wrote:
    >>
    >>> That depends on whether you are testing WOComponents or anything
    >>> else that needs a Request-Response loop (fake or real). For
    >>> general testing and testing EOs, I just use the standard Eclipse
    >>> JUnit launcher.
    >>>
    >>> Are you having specific problems?
    >>>
    >>> Chuck
    >>>
    >>>
    >>> On Apr 8, 2006, at 11:31 AM, Miguel Arroz wrote:
    >>>
    >>>> Hi!
    >>>>
    >>>> What is the correct way of doing unit tests to a WO Project
    >>>> using Eclipse + WOLips? If there any "special" WOLips feature
    >>>> that creates a WO-ready test project?
    >>>>
    >>>> Cumprimentos
    >>>>
    >>>> Miguel Arroz
    >>>>
    >>>> "GUERRA E' PAZ
    >>>> LIBERDADE E' ESCRAVIDAO
    >>>> IGNORANCIA E' FORCA" -- 1984
    >>>>
    >>>> Miguel Arroz
    >>>> http://www.ipragma.com
    >>>>
    >>>>
    >>>>
    >>>
    >>> --
    >>> Coming in 2006 - an introduction to web applications using
    >>> WebObjects and Xcode http://www.global-village.net/wointro
    >>>
    >>> Practical WebObjects - for developers who want to increase their
    >>> overall knowledge of WebObjects or who are trying to solve
    >>> specific problems. http://www.global-village.net/products/
    >>> practical_webobjects
    >>>
    >>>
    >>>
    >>>
    >>
    >>
    >> "GUERRA E' PAZ
    >> LIBERDADE E' ESCRAVIDAO
    >> IGNORANCIA E' FORCA" -- 1984
    >>
    >> Miguel Arroz
    >> http://www.ipragma.com
    >>
    >>
    >>
    >

    -- 
    Coming in 2006 - an introduction to web applications using WebObjects  
    and Xcode     http://www.global-village.net/wointro
    

    Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems. http://www.global-village.net/products/practical_webobjects



    This archive was generated by hypermail 2.0.0 : Mon Apr 10 2006 - 12:47:58 EDT