Test cases (more specially test suites) need to be written in actual code, if they must be documented, document above the test case using POD.

Why? Because you need to run them. Use of any language that is not Perl to write the tests will result in your tests being less flexible than Perl, meaning you are probably going to drop some corner cases through use of some meta language. The group example you gave was rather simple to test, but many things will be much harder. Suppose, for instance, that you have a complex simulation, tons of equations, or (dunno) some sort of ray-tracer. Can you write tests for that in some alien syntax? Probably not.

I just looked at Test::Inline, and (to be fair) the syntax is a little ugly to me. Why? The use of pod to enter and exit code reminds me of C code that is riddled with #ifdef's ... it's very hard to grok the execution path from looking at the source. Further, compilation of one form doesn't ensure the other form is valid code. It's essentially #ifdef'd using POD!

My suggestion ... write the test cases in Perl, and keep them seperate from your main code (in a seperate file if needed). This way, you won't be coding tests that pass your code, since you'll have to think more about your tests. Some programming courses teach "write tests first". Well, I seldom do this (bad flyingmoose!) but the concept is that, this way, you test without preconceptions.

So in conclusion, I think this model would be A) look a lot like ifdef'd code (hard to read) and B) be full of preconceptions since your test cases would be above your code. Also, it would be yet-another-syntax to remember, and, after all, we know Perl. My vote -- keep your tests as code, just document them.

Anyhow, just my fifty three cents. I'm open to debate on this, I just want to play devil's advocate a bit...


In reply to Re: Automatic generation of tests by flyingmoose
in thread Automatic generation of tests by DrHyde

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.