[wp-trac] [WordPress Trac] #42278: Speed up tests by using shared user fixtures

WordPress Trac noreply at wordpress.org
Wed Jan 3 18:26:18 UTC 2018


#42278: Speed up tests by using shared user fixtures
------------------------------------------------+------------------
 Reporter:  Frank Klein                         |       Owner:
     Type:  enhancement                         |      Status:  new
 Priority:  normal                              |   Milestone:  5.0
Component:  Build/Test Tools                    |     Version:
 Severity:  normal                              |  Resolution:
 Keywords:  needs-unit-tests early needs-patch  |     Focuses:
------------------------------------------------+------------------

Comment (by Frank Klein):

 The patch above is a quick and dirty proof of concept that the approach
 outlined in the ticket could work, and that it would not require too many
 changes.

 But it brings a few things to light:
 - I imagine the fixture creation to happen in a class, which is accessible
 in the same way in `WP_UnitTestCase` as the factory. So to use a shared
 user fixture in a test, you could to
 `self::fixtures()->user->get_contributor()` or similar.
 - Currently a lot of tests are opaque because there is already a user in
 the database. This could be made more transparent by using something like
 `self::fixtures()->user->get_count()` when counting users returned by
 queries for example.
 - There are a lot of user fixture creations in tests related to roles. So
 the test just needs a users with a particular role, often to check access
 rights. The shared fixtures could speed up tests significantly by just
 pulling a user object from memory.
 - We would need to fill out all user fields with dummy data, so that tests
 that need things like the nice name or similar could work.

 I do think this is probably worth integrating into the test suite, but I'm
 curious to hear more feedback on this.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42278#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list