Make WordPress Core

Opened 7 years ago

Last modified 2 years ago

#41463 accepted enhancement

Improve REST API tests that don't perform any assertions

Reported by: johnbillion's profile johnbillion Owned by: johnbillion's profile johnbillion
Milestone: Future Release Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: needs-unit-tests needs-refresh
Focuses: rest-api Cc:

Description

There are a bunch of REST API tests that don't perform any assertions. This creates noise in the test results as they get marked as risky tests.

These tests are present because their test class extends the abstract WP_Test_REST_Controller_Testcase class, which requires several methods to be implemented which don't make sense for all REST API routes.

These tests can be improved so they do actually perform assertions related to their behaviour.

Attachments (1)

41463.diff (3.7 KB) - added by johnbillion 7 years ago.

Download all attachments as: .zip

Change History (12)

#1 @johnbillion
7 years ago

  • Owner set to johnbillion
  • Status changed from new to accepted

#2 @johnbillion
7 years ago

In 41176:

REST API: Add some missing assertions to various REST API tests.

See #41463

@johnbillion
7 years ago

#3 @johnbillion
7 years ago

In 41228:

REST API: Populate some missing tests from test cases which extend the controller test case.

See #41463

#4 @johnbillion
7 years ago

Blocked by #41604 and #41605

#5 @johnbillion
7 years ago

  • Milestone changed from 4.9 to Future Release

This ticket was mentioned in Slack in #core-restapi by spacedmonkey. View the logs.


3 years ago

#7 @spacedmonkey
3 years ago

  • Keywords needs-refresh added

The latest patch is from 4 years ago, making this ticket as needs a refresh.

#8 @zieladam
3 years ago

  • Keywords needs-refresh removed

Some time has passed and pulling a fresh list of tests with 0 assertions could be useful here. A fresh (as of today) PHPUnit report is available here:

https://github.com/WordPress/wordpress-develop/runs/3887182312

#9 @zieladam
3 years ago

  • Keywords needs-refresh added

#10 @SergeyBiryukov
2 years ago

In 53921:

Tests: Consistently skip tests for non-implemented methods in REST API test classes.

WordPress core test suite uses PHPUnit's beStrictAboutTestsThatDoNotTestAnything option set to true, which marks a test as risky when no assertions are performed.

REST API test classes have some empty tests for non-implemented methods because these test classes extend the abstract WP_Test_REST_Controller_Testcase class, which requires several methods to be implemented that don't necessarily make sense for all REST API routes.

Some of these empty tests were already marked as skipped, but not in a consistent manner. Since skipping these tests is intentional for the time being, this commit aims to bring some consistency and adjust them all to be more accurately reported as skipped instead of risky.

The skipping can be reconsidered in the future when the tests are either removed as unnecessary or updated to actually perform assertions related to their behavior.

Follow-up to [40534], [41176], [41228].

Props Mte90, tomepajk, johnbillion, zieladam, SergeyBiryukov.
See #40538, #41463, #55652.

#11 @SergeyBiryukov
2 years ago

In 54058:

Tests: Explicitly mark empty REST API tests as not performing any assertions.

WordPress core test suite uses PHPUnit's beStrictAboutTestsThatDoNotTestAnything option set to true, which marks a test as risky when no assertions are performed.

REST API test classes have some empty tests for non-implemented methods because these test classes extend the abstract WP_Test_REST_Controller_Testcase class, which requires several methods to be implemented that don't necessarily make sense for all REST API routes.

As these tests are intentionally empty, they were previously marked as skipped, so that they are not reported as risky.

This commit aims to further reduce noise in the test suite and effectively ignores these empty tests altogether, which seems like a more appropriate option at this time.

The @doesNotPerformAssertions annotation can be reconsidered in the future when the tests are either removed as unnecessary or updated to actually perform assertions related to their behavior.

Follow-up to [40534], [41176], [41228], [53921].

See #40538, #41463, #55652.

Note: See TracTickets for help on using tickets.