Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6652543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:09:09+00:00 2026-05-26T01:09:09+00:00

I have a complex set of PHPUnit tests, some of which involve connecting to

  • 0

I have a complex set of PHPUnit tests, some of which involve connecting to servers around the world that, for whatever reason, timeout sometimes.

Rather than having the test fail when the server times out, I’d like to simply retry that test one or more times before actually marking it as failed.

Now, I understand that this may not be the best way to handle my situation at hand. One better solution would be to fix the servers. But, this is out of my control right now.

So, what I’d really like, is a way to tell PHPUnit to re-test each failing testcase X times, and only mark it as failed if it failed every time.

Any ideas?

Edit: Many of you have responded with helpful suggestions that I not do this. I understand, thank you. However, specifically what I am trying to do is create a test suite that tests the operation of the full system, including the remote servers. I understand the concept of testing certain parts of my code with “mock” responses from the outside…but I also sleep better at night if part of my tests test the “full stack”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:09:10+00:00Added an answer on May 26, 2026 at 1:09 am

    Edit: As per a comment below, this no longer works for PHPUnit 10+.

    As PHPUnit doesn’t support this behavior out of the box, you’ll need to code the loop yourself. Instead of doing it in every test that requires it, create a custom test case base class (if you haven’t already) that extends PHPUnit_Framework_TestCase and provides the feature.

    You can either get fancy and override testBare() to check for an annotation such as @retry 5, loop that number of times, calling parent::testBare(), and swallow all exceptions (or a subset) except the last.

    public function runBare() {
        // I'll leave this part to you. PHPUnit supplies methods for parsing annotations.
        $retryCount = $this->getNumberOfRetries();
        for ($i = 0; $i < $retryCount; $i++) {
            try {
                parent::runBare();
                return;
            }
            catch (Exception $e) {
                // last one thrown below
            }
        }
        if ($e) {
            throw $e;
        }
    }
    

    Or you can create a similar helper method that takes the number of retries and a closure/callable as parameters and call it from each test that needs it.

    public function retryTest($count, $test) {
        // just like above without checking the annotation
        ...
            $test();
        ...
    }
    
    public function testLogin() {
        $this->retryTest(5, function() {
            $service = new LoginService();
            ...
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some complex stored procedures that may return many thousands of rows, and
If you have a complex requirement set with many users(&servers) how will your websocket
I have a fairly complex ASP MVC set of controls that set a data
I have a complex set of bindings that include many private bindings to solve
For my app, I have a fairly complex set of configuration options that user
I have a complex C# method which contains a set of if statements which
Assuming that I have a complex type, for example: interface IFoo { IBar {get;set;}
I have set of Visual Studio solutions which have unit tests. I want to
I have a complex button which is made up of some layouts and Imagebuttons
I have a complex set of data models that currently implement java.io.Serializable , and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.