API page: https://api.drupal.org/api/drupal/core%21core.api.php/group/testing/8.5.x
The Automated Tests topic, which is a @defgroup section in core/core.api.php, needs an update to remove mention of Simpletest from it. Simpletest classes are deprecated.
My suggestion for how to do this:
a) First line: Remove "and Simpletest"
b) "Writing functional tests" section:
- This section is actually mostly about writing Kernel tests, so change the header to "Writing kernel tests (PHPUnit)".
- Remove the first bullet point about Simpletest
- Write a new first paragraph that starts something like this:
Kernel tests extend \Drupal\KernelTests\KernelTestBase, and use PHPUnit as their underlying framework.
And then continue with most of what is currently in the second bullet point (remove that bullet item) that explains a bit about how to use KernelTestBase. It will need some rewording.
- Edit the rest of the bullet points, because they need the information that is currently under the "Writing functional tests (PHPUnit)" section instead, except that the test needs to go in the Kernel subdirectory instead of Functional.
- Remove the link to simpletest docs and replace it with a link to https://www.drupal.org/docs/8/phpunit
d) In the bottom section about running tests, take out the mention of simpletest.
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 2949715-31.patch | 18.56 KB | jhodgdon |
| #31 | interdiff.txt | 1.2 KB | jhodgdon |
| #28 | interdiff-23-28.txt | 874 bytes | jhodgdon |
| #28 | 2949715-28.patch | 18.54 KB | jhodgdon |
Comments
Comment #2
ankitjain28may commentedPlease review, I have fixed the documentation.
Comment #3
jhodgdonThanks for the patch! It is almost there... A few things still need to be updated -- I'll be quoting some sections from the current documentation on https://api.drupal.org/api/drupal/core%21core.api.php/group/testing/8.5.x in these comments...
a) In the previous section about Functional tests, which is now called Kernel tests (good!), it still says;
Both of these are incorrect. The test needs to go in yourmodule/tests/src/Kernel and have a namespace of \Drupal\yourmodule\Tests\Kernel
b) Kind of related... Can you check on the namespaces and directories for the Unit, Functional, and JavaScript test sections too? I think there are some typos.
Good work, thanks!
Comment #4
ankitjain28may commentedFixed, Please review.
Comment #5
ankitjain28may commentedIn last patch, line's length is greater than 80 characters which is fixed in this patch, Thanks
Comment #6
jhodgdonExcellent, thanks! I think this is ready to go.
Comment #7
jhodgdonWhoops, probably this should be 8.6.x.
Comment #8
alexpottThis is very close the section below which is
* @section write_functional_phpunit Write functional PHP tests (phpunit)and that one talks about BrowserTestBase tests. Both BrowserTestBase and KernelTestBase tests are functional tests. I think we need to explain that and why you'd use KernelTestBase. From the documentation that is being removed it says that KernelTestBase tests are for functional tests that do not test web output which seems like a good start for explaining the differences.WebTestBase => BrowserTestBase
Comment #9
ankitjain28may commented@alexpott Can you pls tell me what should be the correct text so that i can make changes and write a correct patch for the issue ?
Comment #10
jhodgdonUmmm...
Regarding comment #8, item 1... The patch already says:
so I think that this comment is somewhat invalid.
However, I think it would be clearer if we made this section have a similar structure to the other sections? We should have an introduction (1-2 sentences) above the bullet list, that explains why we would use a kernel test vs. a browser test vs. a unit test.
So... please take the part of that first bullet point out that explains why you would use a kernel test, and put it into the introduction paragraph instead.
Hopefully comment #8, item 2 is clear? Wrong class name in the patch.
Thanks!
Comment #11
mohit1604 commentedFixing point 2 mentioned in #8.
Comment #13
jhodgdonI forgot about this issue and opened a new one recently: #3029813: Testing topic documentation is way out of date -- it has a more extensive patch... we should close one and credit people who worked on either issue. I'll comment there and we can see what to do.
Comment #14
dwwHere's @jhodgdon's latest patch from the other issue to get us re-started over here.
IMHO, nothing about our testing world, especially not documenting the weirdness, is "novice". ;)
Comment #15
jhodgdonLooking at the two patches... The one that was originally on this issue is outdated (wrong base classes, wrong locations, wrong namespaces), and I much prefer mine that dww uploaded in #14. I don't see anything in the older patch that I think we should transfer over. Other opinions, and reviews of the patch, are of course welcome!
As a note, we need to credit Lendude, dww, and alexpott here, for reviews on the other issue, as well as the people who supplied patches/reviews on this issue.
Comment #16
alexpottI create my directory in
sites/simpletest. I'm not sure thatsites/default/simpletestwould be used. Also two "it".Comment #17
jhodgdonGood catch -- you are correct. Fix for just that...
Comment #18
lendudeHmm this is still not entirely accurate. I would just leave out the 'and have no arguments' and the sentence about @covers and @dataProvider because then you would need to explain the whole when/how/why/why not of that too or leave people with more questions then they got here with. We should elaborate on that in https://api.drupal.org/api/drupal/core%21core.api.php/group/testing/8.7.x or maybe https://www.drupal.org/docs/8/phpunit/phpunit-browser-test-tutorial ? I would opt for the first one because that would allow us to explain that you can and should use @dataProvider for unit and kernel tests, and can but SHOULDN'T use it for functional/javascript tests. And the tutorial would only allow us to explain not using it, which doesn't sound very helpful.
Other then that, this looks like a massive improvement.
Comment #19
jhodgdonThanks for reviewing! My usual method of "write some docs by guessing, then have experts review it for accuracy" seems to be paying off. :)
So, how's this? Regarding @dataProvider, I personally have written one Unit test that used @covers but didn't lend itself well to the data provider way of testing, so I put in the docs "usually use a data provider method".
Comment #20
lendude"usually" might be putting it a bit strong, but not a problem I feel.
Looks great, lets see if others agree.
Comment #21
alexpottI think the text would be better without mentioning data providers - why are we mentioning them here?
Comment #22
jhodgdonI put them in on the suggestion of earlier reviews from Lendude on this and the prior issue. See comment #18 here, and #3029813-10: Testing topic documentation is way out of date
Comment #23
lendudeMy comment in #18 was mostly about just giving some background on why stating that methods have no arguments was misleading, less about putting something about that into the text, sorry if that got lost in translation somewhere :-)
I think dataProviders are a great feature of PHPUnit tests so that is why I had no problems with the text mentioning them, but I get that this might be a little bit more in-depth then this doc should aim for. So here is my stab at taking that bit out.
Comment #24
jhodgdonI thought that the name of the test methods wasn't important after all?
Comment #25
lendudeIt is, it has to start with 'test' or phpunit won't think its a test method.
Comment #26
jhodgdonOK then, I agree with your interdiff. I will go ahead and set this back to RTBC as alexpott's feedback has been addressed.
Comment #27
alexpottThis is a really great clean up. I have one concern...
For me this is too common a situation to not detail in this file. Let's move some of this example into the troubleshooting section. It's far more common that the necessity to do the settings change.
Comment #28
jhodgdonI don't think we need those EXPORT commands, do we? As far as I can tell, running tests lately, this configuration is in the phpunit.xml file and does not need to be in the environment, right? And I have not found it necessary to have the -E on that command line.
So... we already mentioned that you might need to run your tests as the www-data user. But I added an example command line to the troubleshooting section, and separated it from the other information that was in this paragraph.
Thoughts?
Comment #29
lendude@jhodgdom agreed, the export stuff isn't needed. Feedback has been addressed I feel, back to RTBC and lets see if @alexpott agrees.
Comment #30
alexpottIs the double line intentional?
I think this language is a bit strong. This is very much a maybe in certain very rare situations type of thing. I do think it is worth noting here but it's more a try this if you have file permission issues.
Comment #31
jhodgdonWhoops, and good point respectively. :) How about this?
One other thing. There's a bunch of inconsistent formatting in that README file. Should we fix it up in this issue? The stretches of it that were not touched by this patch have >80 character lines (making it really hard to read in a text editor) for instance. And the ``` areas are a mix of indenting and not indenting them. But maybe that would be better to leave for a separate issue?
Comment #32
alexpottLet's do the 80 char thing in a follow-up.
I like the new text.
Comment #34
jhodgdonGuess this should be RTBC for #32?
Also made a child issue for the formatting #3038378: README.md in core/tests is badly formatted
Comment #36
jhodgdonComment #37
alexpottCommitted and pushed 446586b60a to 8.8.x and 4a701c007a to 8.7.x. Thanks!
Comment #41
joachim commentedThis patch removed all mention of selenium:
Could someone explain why -- did it cease to be needed, and if so, for which version of Drupal core?
If older versions of core do need it, then https://www.drupal.org/docs/8/phpunit/running-phpunit-javascript-tests should mention that.