On Tue, Oct 04, 2005 at 05:45:13AM -0400, Tom Allison wrote:

> This isn't a test message sent to the list, that would be lame. ;)
> 
> However it's all about Testing and how to do it the right way.
> 
> I've been trying to use Test::More as the cornerstone of my testing.
> This kind of falls into a pseudo-philosophical discussion of how to code 
>  but I'll try really hard to keep it focused.
> 
> I can generate tests well enough for Modules and Object packages but 
> it's evaluating the answer or Mocking that I'm uncertain.

Your questions are answered in chapters 5 and 9 of Perl Testing: A
Developer's Notebook.  If you want to test with Perl I recommend it
highly.

> It seems that there really isn't any clear way to test a subroutine 
> within a script and not a module.  Besides loading it into a module and 
> running everything from there -- any suggestions?  I don't see it 
> practical putting a function into a module when the function will only 
> ever be used in that one script.

The solution presented in chapter 9 is to ensure there is no code in
your script outside of subroutines - put the main body of the code in
sub main().  Then add to your script:

  main (@ARGV) unless caller();

Your tests my then safely require the script and test its subroutines.

> It is my "pseudo-philisophical" approach to programming that if I use a 
> block of code more than one/two times in a script I make it a function. 
>  If I use a function in more than one (or two) scripts I make it a 
> module.  Thats the extent of my philosphical discussion of how to program.
> 
> Unfortunately not all of this fits well with Test::More.
> 
> As for MOCK:  How would I Mock IMAP server connections?
> A starting point... ?

Chapter 5 talks about this and introduces Test::MockObject.

The basic idea is that you write methods which are used instead of the
standard methods and which return plausible output to your tests,
presumably without going to the bother of writing or using a real IMAP
server.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to