Tuesday, May 13, 2014

Please don't create tests like this in Perl

I just came across a test like:

And of course, it was silently doing something/nothing/everything. I'd guess most experience Perl coders will notice that the eval will only run the test if the request doesn't throw an exception. Which might be kind of ok but there is no catch or check of the $@ later.

If a check is added for $@ later, it will make the test pattern pretty messy

Please don't write this type of test. Please.

Instead use Test::Exception and drop into a sub. Something along the lines of:

This is better for a couple of reasons:
  • test will show some output in case of exception
  • test will stop instead of just pushing on with a bunch of mostly false error (unless the test wants to this to check bad input :)
  • test is simpler to understand (no response, give up)


  1. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..

    Digital marketing company in Chennai

  2. Your article looks good. I wondered by reading this blog post. Thanks a lot for posting this unique post which you have shared with us. Keep on posting like this exclusive post with us.

    Branding Services in Chennai

  3. thank you for sharing such a nice and interesting blog with us. hope it might be much useful for us. keep on updating...
    ROI Services in Chennai

  4. Nice Blog

    Telugu70mm.com Provides Latest Telugu Movie Reviews and other news like Telugu Movie News , Telugu Political News and Movie Released Dates

  5. Thanks for appreciating. Really means and inspires a lot to hear from you guys.I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..Believe me, This is very helpful for me.

    SEO Company in India|Digital Marketing Company in Chennai