Re: Test driven design and graphics in Java

Discussion in 'Java' started by Daniel Pitts, Apr 18, 2008.

  1. Daniel Pitts

    Daniel Pitts Guest

    Kenneth P. Turvey wrote:
    > On Fri, 18 Apr 2008 09:55:26 +0200, Andrea Francia wrote:
    >> Kenneth P. Turvey wrote:
    >>> I also know that the answer for GUIs is often "don't test the view".

    >> This is a bad advice. Every requirements of the software should be
    >> tested, also those that are difficult to test in automatically.
    >> When you can test automatically a feature you should test it manually.

    > That's really what I meant.. no automated test. I guess that's where I
    > am right now. Some of my tests are going to have to be manual tests.

    With "Test Driven Development", you write the a test first, and then
    write the minimum amount of code to make it succeed.

    This is NOT a testing methodology. Proper testing needs to find all edge
    cases and problems. TDD is used to ensure that certain features work as
    you expect them to, without interfering with other preexisting features.

    This is indeed difficult for GUI/Graphical interfaces. I found the best
    I could do is just assume that GUI interface is a one-to-one call into
    the controller/model API, and testing *that* interface should be "good

    In other words, don't test "User Clicks Button". test "Event Fired When
    User Clicks Button"

    Daniel Pitts' Tech Blog: <>
    Daniel Pitts, Apr 18, 2008
    1. Advertisements

  2. Mark Space

    Mark Space Guest

    Kenneth P. Turvey wrote:

    > I understand all this, but I'm really working on a graphical
    > application. The problem isn't really to test whether a single event is
    > fired. The problem is to determine if an image has been altered
    > correctly when a certain sequence of events happen... or something
    > similar.

    I may not be understanding correctly here, but the first thing that
    occurs to me is to yoink the methods that perform these graphical
    calculations out of the view, and place them in a separate class that
    can be tested easily. Get rid of the Graphic2D object and other Swing
    objects (although you might have to keep Image).

    Then once that class is unit tested, it becomes a matter of integration
    testing when you compose the view with a real graphics object, but that
    can be done much more coarsely.

    I think is see what you mean by "test is similar the method being
    tested." To test if a method makes an Image 50% darker, you need an
    image that's 50% darker to test against. Hmmm, not sure there's a way
    around that....

    You might want to be concerned with things like boundary conditions
    (memory, pointers, indexing) in the unit test and use some other method
    for the calculations themselves. Code review + mathematical proof perhaps?
    Mark Space, Apr 19, 2008
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yan-Hong Huang[MSFT]
    Yan-Hong Huang[MSFT]
    Oct 15, 2003
  2. Nick Zdunic
    Nick Zdunic
    Nov 5, 2003
  3. Sasha
    Scott Allen
    Mar 2, 2005
  4. José María

    Domain Driven Design and Python

    José María, Apr 16, 2009, in forum: Python
    Terry Reedy
    Apr 18, 2009
  5. Mayank Srivastava
    Brian Candler
    Mar 20, 2007

Share This Page