How to avoid "'do/while/for' statement does not loop" warnings when attempting to always execute a call when exiting it?

19 views Asked by At

I'm developing some Test scripts that always log a all of the successes/failures of the Testcase steps up to that point to my Test app of choice (and end the test as soon as there's a failure). So I put my calls to tests on each page that the Testcase hits inside a loop and break out of it if one of the tests detects a failure. The call to record the test step results are right after the loop. However... IntelliJ seems peeved that my loops are not looping and shows a warning every time I do this - which adds up to a lot of warnings.

Here is an example of one of my Testcases:

For example:

@Test
public void invalidContactReceiver()
{
    // Get Test Run data.
    HelperFunctions.getTestRunInfo(...);
   
    while (true)
    {
        // Grab the timestamp, it is used when reporting the results.
        startTime = Stopwatch.createStarted();
      
        // Open App under Test and login.
        LoginScreen appLoginScreen = new LoginScreen();
        GenericAppPage bottomBar = appLoginScreen.waitForAppToOpen();
        if (bottomBar == null) break;

        // Go to the Contacts tab.
        ContactsPage cPage = (ContactsPage) 
        bottomBar.goToAnotherPage(PageType.Contacts);
        if (cPage == null) break;

        // Check Receiver Contact validation.
        if (!cPage.invalidValueCheck(true)) break;
      
        // Test is done, so exit the loop.
        break;
    }

    // Record results.
    recordResults();
}

Result is a "'while' statement does not loop" warning from IntelliJ.

So... what's the alternative? If statements do not allow 'break', there's no GOTO, It feels like IntelliJ wants me to remove the loop and replace every instance of 'break;' with 'recordResults();' - but that seems like bad design - if I have to change name of the recordResults function in the future - it makes updating all of the calls a more daunting possibility. Do I just ignore the warnings? Or is making the call to that function after every bad Test result really the expected way to handle this?

0

There are 0 answers