Re: lots of quick tests that have very low cost but uncertain value



Michael Bolton wrote:

In answer to your descripition of "inaccurate tests".  I don't know
what you mean by inaccurate tests, so you can define them as you like.
:)  Do you mean "useless tests"?  Tests that are based on erroneous
presumptions?  Tests that ignore things like system requirements?
Tests that could not conceivably matter to anyone?  Tests that do not
address some risk?  Such tests can exist, but I don't think I would
call these "inaccurate"; perhaps "inappropriate" or "unhelpful" or
"(probably) valueless". But you may have something else in mind.

Suppose I write a complex GUI, such as a web browser.

The lowest level of such a system is a Paint() event (a WM_PAINT in Windows,
a Paint(Graphics g) in Java, etc.).

The Paint() event always passes to the programmer a reference to a graphics
device context. This behaves kind of like MsPaint, with a toolbar of
brushes and colors, and a raster. A complex Paint() event handler will pick
a brush, and draw a sequence of colored strokes on the raster.

Suppose I write a Paint() event that paints Red over here, and Green over
there.

To unit test this, create a mock graphics device context. Some systems
expose a "metafile" system, to spool graphic commands for later replay.
Some systems let you create a mock object out of the Graphics object. I
think Google will return hits for "mock graphics" here.

Unit tests now set up the web browser, call the Paint() event, and collect a
big long string or list of canned graphical commands. All intercepted from
going into a real raster.

A cheap test on such a string (a "log string test") doesn't need to
reconstitute the raster and "look at it". The test could trivially check
the list contains a Red stroke, some more operations, and then a Green
stroke.

Now suppose we perform a clean, dainty refactor on our code. It still paints
Red, then Green, and the test passes.

Now suppose we perform a sloppy refactor, or we add a feature. We twiddle
the code, maybe move a calling function, and now the Paint() event paints
the Green stroke first, then the Red stroke.

If the strokes were supposed to overlap, the user would now perceive a bug.

If they don't, then the user doesn't care what order the strokes go. (Maybe
the system uses masks and stencils, so the stroke order is less relevant.)

As programmers (and testers), keeping the tests cheap is more important than
making them perfect. The test should not pass _any_ Red and _any_ Green,
because this is easier to break in a bigger way. The test _cannot_ render
an entire raster and look at it, because AI is klutzy enough for production
code without burdening test code with it too.

The tests should force us to back out our change and try again - _even_ if
the change itself caused no real bug.

(Those of you seething about over the TDD references should be assured that
these situations matter at all scales, including the acceptance tests.)

So Achilles leaps over the turtle and declares where it will stop. The
turtle stops there, and a higher level of testing is achieved.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
.



Relevant Pages

  • Re: Re: Can I change color of clipart inserted into Publisher document?
    ... Paint is a breeze but the colours are limited.. ... A single colour jpg changes colour in Publisher very easily, ... Paint shop Pro I use purely to convert graphics ... Microsoft Clipart organiser.. ...
    (microsoft.public.publisher)
  • RE: P.S. Custom control repaint
    ... After I made several modifications on your code and the drawing behaves ... Dim PictBoxGraphics As Graphics ... Dim rectCanvas As Rectangle ... PictureBox1's Paint event pass the PictureBox1's Graphics object with its ...
    (microsoft.public.vsnet.general)
  • Re: Inserting text onto jpeg
    ... Any photo or graphics editor should have the ability to insert text over the ... This includes Microsoft Paint. ... [END QUOTE] ... Other programs worth looking at are the 30 day trial versions of ...
    (microsoft.public.windowsmedia)
  • Re: compare string lenth to text box drawing area
    ... I used the TextBox.CreateGraphics() method to get the graphics for instance. ... I had to keep a form-level bool to know whether the Paint ... > private void MoreText_MouseLeave(object sender, ... >> PS) My example was done from a Paint event (that's why the e.Graphics ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how to paint straight lines, evenly colored?
    ... you can stroke paths and/or selections. ... I used the pen tool to paint a path, ... >> you can also paint straight lines with the brush by making a starting ...
    (alt.graphics.photoshop)