in reply to Testing A Stand Alone Application

Before you decide where your going to put your tests, what in this sample are you going to test?

I appreciate that the snippet is intended to promote replies about how to go about testing a stand alone script, not how to test this particular example. But in the absence of any real code, it is pretty much impossible to suggest good ways of testing.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Testing A Stand Alone Application
by est (Acolyte) on Mar 13, 2008 at 00:06 UTC
    Hi BrowserUk,

    Thanks for the comment...
    As you have mentioned, my aim is to promote a reply on how to test a stand alone script , i.e. not to test the example I provide in my post.

    And what I intend to do is to get used to write the test first before the actuals coding, as what is suggested by PBP chapter 18.1:
        So write the tests first. Write them as soon as you know what your interface will be.
    Write them before you start coding your application or module.

    The impression I get from your comment
        But in the absence of any real code, it is pretty much impossible to suggest good ways of testing.
    
    is that you need to code first, so you know what to test later.

    The example I provide in my post is supposed to be the interface I'll use...


    Thanks.

      My point was that in the code you've posted, there is nothing to test, so it's hard to demonstrate any mechanism for testing it.

      The example I provide in my post is supposed to be the interface I'll use...

      Interface to what? So far, the code does nothing, and you've provided no indication of what it should do. To write tests first, you have to have to know what the end point (or an intermediate point) is going to be, so that you can construct a test to verify that when yu write the code, you have achieved it.

      For example, you've indicated that you'll be processing XML files some how. But how?

      • Will you be generating structure?

        If so, you might verify that structure.

        Maybe, by feeding in a known XML and hard coding a structural equivalent to verify against.

      • Will you be transforming the input to some output? A different XML? CSV?

        If so, you might test by feeding in a known XML and comparing the result against a hand-coded output.

      You (we) gotta know what you are aiming for before you can construct a test that will check your code, when you write it, achieves that.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Ahhh fairynuff, I should have provided more information about the interfaces... okay, there you go:
        • get_xml_files
          1. input: a (exist) directory
          2. objective: glob all xml files in the directory
          3. output: a list of filename.xml or empty list
        • extract_file
          1. input: a list of xml files
          2. objective:
            1. parse the xml file (using XML::Simple)
            2. find a specific tag, e.g. IMPRESSIONS
          3. output: write to STDOUT the filename.xml and the IMPRESSIONS found

        I think that should answer your question about the interface? I know that functionality can be done in one line by
            grep IMPRESSIONS *.xml
        But again it's only an example...