I'm wondering how fellow monks test in regards to the outputs of functions. By output, I mean longer string output that's generated to appeal visually to the user.

I have a class that does it's thing, you know, holds data, has methods, the usual things a class does - nothing to amazing. The class also has an 'output' method, so $obj->output; will output its information in a human-readable form. I've also subclassed this class for output purposes, ie, Foo::HTML overrides the output method so $obj->output; will output in HTML format, and Foo::XML will output in XML; and if I ever would want to do something like Foo::Tk, the possibility is there. Now, when writing tests for my class, I have written good tests for almost all of my methods so I can be sure they do what they claim, but what about these output methods?

One thought would be to do something like:

is( $obj->output, qq(<div class="Foo">&lt;Relevant Info&gt;</div>) );
But then everytime I want to change my html output slightly, I would have to rewrite my tests to succeed (and it should be the other way around... rewrite the code so the tests succeed).

The way I'm doing it right now (since I'm still trying to figure out what I want to do), is check that the output is defined and not equal to "".

So, what's the best way to check output? Do you decided absolutely what the output will look like at the beginning of the project and hardcode it into a test? Do you just ignore testing output, and look at the output after every change? Do you do something completely different?

I'm eager to hear what most other monks do! Thanks in advance.

Update:
It has come to my attention (thanks thcsoft)that the question may not be clear. Let me think about this for a moment. Must be one of those things where it makes sense in my head what I'm asking, but not to others.

Okay, what I'm getting at is that my class generates up to 10 lines of output, formatted as HTML, based on the current state of the object. It doesn't seem reasonable to hardcode this 10 lines of output into a test, especially if I plan to make minor aesthetic updates later on. So how is longer output like this generally tested? Or is it tested?

I don't know if that makes it any more clear, I hope it does.

    -Bryan


In reply to use Test; and output by mrborisguy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.