Problem/Motivation
#3386448: Get rid of InstallUninstallTest is a single test that installs every module, then runs some standard checks.
HelpTopicsSyntaxTest is another one.
While these catch issues in modules that otherwise might not add their own coverage, they're very inefficient in that a single test run can take several minutes to complete. They also inherently don't enable contrib to test the same things.
Steps to reproduce
Proposed resolution
Add GenericModuleTestBase, this should require only an empty subclass.
This test would then install and uninstall the module, check hook_help(), and possibly other things that we'll think of later.
Then all core modules (but not test modules) can implement the test.
If we still want to ensure coverage of all core modules, we could add a unit test that discovers whether all non-testing modules have a subclass of this test.
namespace Drupal\Tests\my_module\Functional;
use Drupal\Tests\system\Functional\Module\GenericModuleTestBase;
/**
* Generic module test for my_module.
*
* @group my_module
*/
class GenericTest extends GenericModuleTestBase {}
Remaining tasks
Add tests per module, this should be scriptable since the only difference between the test files is the module name.
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3386458
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
alexpottI've been thinking about this issue for ages. It'd be fantastic if Drupal shipped with a generic test that could easily be extended by any contrib or custom module that wanted to make sure it's working under common circumstances - for example a reinstall scenario.
Comment #3
catchComment #5
catchHere's a start.
Adds GenericModuleTestBase. System and DbLog modules subclass it.
Tests hook_help() and uninstall/reinstall.
I started to look at moving HelpTopicsSyntaxTest over to this, but it relies on all modules being installed, not just the one being tested, so I think that's better left in its own test. Maybe we can factor bits out but should be its own issue.
Comment #6
catchIdeally:
1. Agree on the naming/namespace etc. - it could move to core/tests but then the dependency on help module seems a bit odd.
2. Once what's here is reviewed, add subclasses for all core modules. Might make an OK novice task.
Comment #7
alexpottShould the generic test somehow be extendable in some way?
Comment #8
catchThis crossed my mind but no idea how. We can't rely on subclasses because we want people to inherit from one class then get new test methods/assertions for free, so needs to be a single central class not with functionality spread around modules. Same problem with adding various traits. Adding some kind of event system to tests so that help can add its assertion in seems like overkill.
Comment #9
alexpottI think we can park the extensibility discussion - I think it is okay for the focus of this issue to be to add a base class to core that can test any API provided by anything we include in the drupal/core package including optional modules like help. And if we want to extend/refactor this using PHPUnit's events or something like that in future then we can.
Comment #10
smustgrave commentedAre the namespaces off?
Comment #11
catchThey were indeed.
Comment #12
smustgrave commentedWoo that was it!
Comment #13
catchI think we either need to add subclasses for all core modules here, or open a follow-up to do that, before this can be committed.
Comment #14
smustgrave commentedSo I would vote for a follow up and maybe a CR?
The ticket for subclasses could get large I imagine and a lot back n forth. But getting this merged could allow contrib modules to start using.
Thoughts?
Comment #15
alexpottI think given the tests should not have any logic in them it'd be great to add them here. Plus we could add a test to ensure any new non test modules has such a test.
Also adding this to all modules in core is likely to help us discover if there are any issues with the base class.
Comment #16
smustgrave commentedGot me convinced @alexpott.
updated remaining tasks
Comment #17
catchI think testing all core modules here is good, but for me I would put 'testing the test coverage' into a follow-up since this is a blocker for gitlab ci performance improvements.
Comment #18
catchAdded the magic. I thought about it when adding the property and rejected it initially since it could be hard to document, but it results in an empty class so really, what is there to document then?
Comment #19
catchMoving back to needs review - once we're happy with what modules have to do, we can tag this novice for applying the pattern to all core modules, but would be good to be fairly confident about that before we do it.
Comment #20
catchComment #21
catchComment #23
quietone commentedAdded tests for all modules. Also, remove 'Currently' from a sting because I thought it was superfluous.
Comment #24
borisson_Having this test coverage would make it more easier to rtbc this issue, and I think it would be very helpful to have. However because this is already a big boost I agree we shouldn't wait for this.
Comment #25
dqdMinor comment language nit-pic for non native tongues:
Is the comma meaning "required modules, which are hidden" or is it like "for hidden and for required modules"?
Comment #26
alexpottThe test unfortunately is not currently testing the module we hoped it was... see code comment on MR.
Comment #27
catchFixed the very silly thing. Added a new empty method to the base class preUninstallSteps() and implemented that in forum and workspaces.
Comment #28
catchBack to needs review, changes from #27:
Add @group legacy to the tracker and help_topics subclasses because both are deprecated.
Handling the fact that the current database driver can't be uninstalled.
Comment #29
catchhelp_topics no longer implements a standard hook_help() because it's informing people its deprecated, so removing that test. Tracker test works with @group legacy.
Comment #30
smustgrave commentedAll green, and seems all threads have been addressed. Marking but would this need a CR?
Comment #31
catchAdded change record: https://www.drupal.org/node/3388092
Comment #32
larowlanLeft some comments
I think we need to perform some asserts when we do the uninstall/install step
I also think we would want a unit test to make sure every module has one of these tests.
Comment #33
quietone commentedAdded the unit test, which will fail because the test was removed from help_topics. I didn't add that back so we can have a fail test for this change.
Comment #34
quietone commentedAdd a parameter to the test to list the modules that do not have a GenericTest. It seemed the simplest solution.
Comment #35
catchI was dreading adding the unit test because I figured we'd need to discover all functional tests and look for a subclass. Just looking for the class name is of course fine because this is core and we can control it.
Comment #36
wim leersComment #37
catchNeeds work for @alexpott's two points.
Comment #38
catchYes unit test takes 1 second with the data provider. Pushed a commit for that.
Comment #39
smustgrave commentedAll threads do appear to be resolved, so remarking.
Comment #40
larowlanCommitted and pushed to 11.x
It doesn't apply to 10.1.x so can't backport it, setting to Patch (to be ported) to discuss whether we want to do that?
HelpTopicSyntaxTest is where the conflict is
Comment #42
catchReasons to backport:
1. Contrib will be able to use the new base class 6 months quicker.
2. 10.1.x commit/scheduled runs (and the occasional MR) will be faster, especially if we keep backporting other changes.
I think those are both good enough reasons so opened a backport MR against 10.1.x. Merge conflicts were just a code comment.
Comment #43
smustgrave commentedThink that 100% makes sense, could we get a 10.1 MR?
Comment #44
catchComment #46
smustgrave commentedSweet
Comment #47
larowlanBackported to 10.1.x
Comment #50
grevil commentedHey everyone! Thanks for this, we were always manually implementing install / uninstall tests for all of our modules. This definitely solves this problem!
Although I have a few questions on "GenericModuleTestBase":
Just a few questions to stir up a small, friendly discussion! Have a nice day, everyone! 😊
Comment #51
larowlanIf you have ideas for improving the work here, please open new issues, definitely keen to improve things if there are issues