Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Testing Interactive Interface?

by pirkil (Beadle)
on Oct 18, 2013 at 08:20 UTC ( #1058721=perlquestion: print w/replies, xml ) Need Help??
pirkil has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I have a program which uses Term::ReadLine in order to set input options interactively. I can't present the code, so my question/meditation is a bit gnomic, I know. However, there are several options for the script, so the user is first being asked for the input file, then for the output destination, etc.

Now I need to extend my test to cover this behaviour. How can I simulate an interactive process from the test? I would appreciate any suggestions, thank you.

Replies are listed 'Best First'.
Re: Testing Interactive Interface?
by moritz (Cardinal) on Oct 18, 2013 at 08:57 UTC

    There are several approaches:

    • Make the interactive parts optional, for example accept command line arguments, and only ask interactively if command lines are missing. Simplifies testing and automation a lot.
    • Make the code an object on which it calls the ->readline method, and only create a Term::ReadLine object in its place if no such object was passed. That makes it easy to supply a "fake" Term::ReadLine object of your own creatin in the test code (that's called "dependency injection").
    • Automate the whole thing across a process boundary with Expect-like modules.

    I'd certainly go with the first option if possible, and fall back to the second option if ithe first isn't applicable.

Re: Testing Interactive Interface?
by GrandFather (Sage) on Oct 18, 2013 at 08:30 UTC

    Use Test::MockObject to mock up whatever you need from Term::ReadLine. I can't present any code, so my answer is a bit gnomic, I know. However, I'm sure you'll figure it out.

    True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1058721]
Approved by GrandFather
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2018-05-26 08:25 GMT
Find Nodes?
    Voting Booth?