Opened 9 years ago
Last modified 3 weeks ago
#40538 accepted task (blessed)
Fix or remove useless PHPUnit tests
| Reported by: | johnbillion | Owned by: | johnbillion |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Build/Test Tools | Version: | |
| Severity: | normal | Keywords: | needs-unit-tests ongoing has-patch |
| Cc: | Focuses: |
Description
There are 29 tests in the test suite which don't perform an assertion. They should be fixed or removed.
PHPUnit 6 has switched to being strict about useless tests by default, so that gives us an additional reason to address them. In addition, there's no reason for core's default PHPUnit configuration to not be strict about useless tests so the same behaviour is seen when running older versions of PHPUnit.
Previously: #36016
Attachments (2)
Change History (17)
This ticket was mentioned in Slack in #core by obenland. View the logs.
9 years ago
#8
@
9 years ago
- Keywords needs-unit-tests ongoing added
- Milestone 4.8 → Future Release
There are still a bunch of tests that don't perform any assertions.
#9
@
9 years ago
- Keywords has-patch added
This patch remove the empty units for 4 tests :-)
Are missing:
There were 4 risky tests: 1) WP_Test_REST_Pages_Controller::test_prepare_item This test did not perform any assertions 2) WP_Test_REST_Settings_Controller::test_context_param This test did not perform any assertions 3) WP_Test_REST_Settings_Controller::test_prepare_item This test did not perform any assertions 4) WP_Test_REST_Settings_Controller::test_get_item_schema This test did not perform any assertions
I am not sure about prepare, context and get_item_schema tests about what they have to do.
#10
@
9 years ago
Thanks for the patch, @Mte90. AFAICT these tests are actually blocked by a bug I found when working on #41463. See 4:ticket:41463.
This ticket was mentioned in Slack in #core by tomepajk. View the logs.
8 years ago
@
8 years ago
tests for WP_Test_REST_Pages_Controller::test_create_item and WP_Test_REST_Pages_Controller::test_get_item
#14
@
3 weeks ago
Updated count for August 16, 2026
trunk today has 101 occurrences of @doesNotPerformAssertions across 26 files:
- 88 in 20 files under
tests/phpunit/tests/rest-api/ - 13 in 6 files elsewhere, but 5 of those are also REST controllers, under
icons/andfonts/font-library/. Onlyuser/passwordHash.phpis unrelated. - It has spread into directories that did not exist when [53921] and [54058] applied it, so the count grows with each new controller rather than staying flat.
Looks structural rather than per-test: WP_Test_REST_Controller_Testcase declares nine abstract methods, including test_create_item(), test_update_item() and test_delete_item(). Read-only routes cannot assert on those. The themes controller docblocks read "The create_item() method does not exist for themes."
The strictness from [40534] is intact: beStrictAboutTestsThatDoNotTestAnything and failOnRisky are both still true.
Two tasks:
- Make the abstract reflect read-only routes, so new controllers stop inheriting this.
- Per-case read for tests that could assert but do not.
#15
@
3 weeks ago
I created this AI skill to help with unit tests audits: https://github.com/WordPress/core-contributor-skills/tree/trunk/skills/unit-tests
Works with both Claude and Codex
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
In 40534: