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:
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).is( $obj->output, qq(<div class="Foo"><Relevant Info></div>) );
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |