WebAssert Tests do not actually test all methods

Created on 19 July 2024, 5 months ago
Updated 23 August 2024, 4 months ago

Problem/Motivation

In 📌 Convert WebAssertTest to a Unit test Needs review it was discovered that a few methods that several test methods do not actually make assertions so the test coverage of the tests do not actually work.

These three are identified as claiming coverage but not actually covering them:

  • linkExists
  • assertEscaped
  • responseContains

Further there are several methods not covered.

  • optionExists
  • buildXPathQuery
  • optionNotExists
  • titleEquals
  • assert
  • fieldDisabled
  • fieldEnabled
  • hiddenFieldExists
  • hiddenFieldNotExists
  • hiddenFieldValueEquals
  • hiddenFieldValueNotEquals
  • statusMessageExists
  • statusMessageNotExists
  • statusMessageContains
  • statusMessageNotContains
  • buildStatusMessageSelector
  • responseHeaderEquals
  • pageTextContains
  • fieldValueEquals
  • selectExists

Steps to reproduce

Break linkExists (e.g. throw an exception or other breakage)
Run tests
Tests pass

From #3454092-26: Convert WebAssertTest to a Unit test
Found out why those assert methods that make no assertions are passing in BrowserTestBase tests:

In BrowserTestBase::setUp:

// Ensure that the test is not marked as risky because of no assertions. In
// PHPUnit 6 tests that only make assertions using $this->assertSession()
// can be marked as risky.
$this->addToAssertionCount(1);

Proposed resolution

Ensure mentioned methods have full coverage.

Remaining tasks

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
PHPUnit 

Last updated about 3 hours ago

Created by

🇺🇸United States nicxvan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @nicxvan
  • 🇺🇸United States nicxvan
  • 🇺🇸United States nicxvan
  • 🇺🇸United States nicxvan
  • 🇬🇧United Kingdom joachim

    Well spotted!

    At the very least the comment that mentions a totally outdated version of PHPUnit needs to be updated!

  • 🇺🇸United States nicxvan
  • 🇦🇺Australia mstrelan

    I think there are two separate issues here, not sure if we need to split this. One issue being that ::linkExists (and similar methods) do not add anything to the assertion count. The other is that WebAssertTest doesn't cover everything in WebAssert.

    To highlight the first issue, I've put up an MR that undoes the workarounds added in 📌 Convert WebAssertTest to a Unit test Needs review . When this was a functional test it was passing because BrowserTestBase::setUp increments the assertion count. Now since the assertion count is 0 we get a risky test reported.

    To fix this we can replace calls to $this->assert() with code like Assert::assertNotEmpty() and similar methods.

  • Pipeline finished with Success
    5 months ago
    Total: 450s
    #245100
  • Status changed to Needs review 5 months ago
  • 🇦🇺Australia mstrelan

    Apparently our CI doesn't complain about risky tests, but if I run them locally it does. Anyway, I've replaced all calls to $this->assert but noticed this changes the behaviour in that we're no longer throwing exceptions. I think that's probably a good thing, but maybe it's not great for BC. Alternatively we could change WebAssert::assert() to call Assert::assertTrue((bool) $condition, $message); but again, that has BC implications. Not sure where to go from here.

  • Pipeline finished with Failed
    5 months ago
    Total: 636s
    #245108
  • Pipeline finished with Success
    5 months ago
    Total: 570s
    #245122
  • Status changed to Needs work 4 months ago
  • 🇺🇸United States smustgrave

    So from what I can tell some methods are being completely removed like testInvalidLinkExistsExact. Even though not used can we be sure they aren't used in contrib? May have to deprecate just to be safe.

    That said if easier this maybe could be broken up for smaller chunks. Dealers choice.

  • 🇦🇺Australia mstrelan

    So from what I can tell some methods are being completely removed like testInvalidLinkExistsExact.

    That is one of the tests being removed from WebAssertTest, not a method removed from WebAssert. They're removed because they no longer make sense since the methods are refactored.

    That said I think we need to figure out what should be done here and what should be done in #2805849: WebAssert does not track assertions, Test marked as risky .

Production build 0.71.5 2024