in reply to Re^2: How can I make DBI's prepare() fail? [MySQL]
in thread How can I make DBI's prepare() fail? [MySQL]

Let me try to reiterate. The "mock" testing strategy would mean preparing three different mock objects, one failing each particular call you want to handle failure of and succeeding others. First you would set connect() to fail, run your code and check whether the error handling subroutines are called. Then you would restore normal behaviour of connect() (see also: DBD::Mock to allow testing database error handling without a live database) but set prepare to fail and run your code again. Lather, rinse, repeat until all error conditions you want to be able to handle are tested.

Replies are listed 'Best First'.
Re^4: How can I make DBI's prepare() fail? [MySQL]
by Cody Fendant (Hermit) on Apr 04, 2019 at 22:51 UTC

    I think there was a fundamental misunderstanding here, possibly caused by my wording.

    Your answers are perfectly good answers to "how should I create a test so that I can see what happens if a particular function fails?", which is one interpretation of my question.

    However my question is really "how can I make real-life code fail at the prepare() stage if the SQL code is bad?"

    kschwab's answer here is the answer to the question I was trying to ask.