Most tests extend DrupalWebTestCase and not DrupalUnitTestCase because they have to access the database etc.. However most tests for stuff in /includes (not including /includes/database) can possibly use DrupalUnitTestCase. unicode.test is one such example. There's potential to shave a few minutes off every test run.

Comments

dalin’s picture

Issue tags: +Novice
dalin’s picture

Status: Active » Needs review
StatusFileSize
new5.47 KB

Found 10 instances. Not quite as many as I expected. But should save about 2mins per test run.

Status: Needs review » Needs work

The last submitted patch, 984874-2-DrupalUnitTestCase.diff, failed testing.

dalin’s picture

Status: Needs work » Needs review
StatusFileSize
new4.5 KB

That's what PIFR is for I guess - to catch our mistakes.

sun’s picture

Issue tags: +Testing system
Niklas Fiekas’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
Issue tags: +Needs backport to D7

Looks awesome. This would have to go into 8.x first. Needs a reroll.

LSU_JBob’s picture

Status: Needs work » Needs review
StatusFileSize
new3.91 KB

rerolled for 8.x, picked up from novice queue

sun’s picture

Status: Needs review » Needs work
+++ b/core/modules/simpletest/tests/common.test
@@ -73,7 +73,7 @@ class CommonDrupalAlterTestCase extends DrupalWebTestCase {
  * url() calls module_implements(), which may issue a db query, which requires
  * inheriting from a web test case rather than a unit test case.
  */
-class CommonURLUnitTestCase extends DrupalWebTestCase {
+class CommonURLUnitTestCase extends DrupalUnitTestCase {

The comment right above the class definition explains why it's not a unit test.

+++ b/core/modules/simpletest/tests/theme.test
@@ -118,7 +118,7 @@ class ThemeUnitTest extends DrupalWebTestCase {
  * Unit tests for theme_table().
  */
-class ThemeTableUnitTest extends DrupalWebTestCase {
+class ThemeTableUnitTest extends DrupalUnitTestCase {

Theme function tests are functional tests and not unit tests by design, as they rely on the theme registry, and we don't want to test the theme registry or behavior of the parent site that is executing the test.

LSU_JBob’s picture

Status: Needs work » Needs review
StatusFileSize
new2.96 KB

okay, reverting those two back.

jbrown’s picture

jbrown’s picture

Status: Needs review » Reviewed & tested by the community

I think this could be committed.

sun’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/simpletest/tests/common.test
@@ -524,7 +524,7 @@ class CommonSizeUnitTestCase extends DrupalUnitTestCase {
-class CommonAutocompleteTagsTestCase extends DrupalWebTestCase {
+class CommonAutocompleteTagsTestCase extends DrupalUnitTestCase {

@@ -2171,7 +2171,7 @@ class CommonSimpleTestErrorCollectorTestCase extends DrupalWebTestCase {
-class CommonDrupalParseInfoFileTestCase extends DrupalWebTestCase {
+class CommonDrupalParseInfoFileTestCase extends DrupalUnitTestCase {

+++ b/core/modules/simpletest/tests/unicode.test
@@ -8,7 +8,7 @@
-class UnicodeUnitTest extends DrupalWebTestCase {
+class UnicodeUnitTest extends DrupalUnitTestCase {

OK

+++ b/core/modules/simpletest/tests/common.test
@@ -1035,7 +1035,7 @@ class CommonDrupalHTTPRequestTestCase extends DrupalWebTestCase {
-class CommonRegionContentTestCase extends DrupalWebTestCase {
+class CommonRegionContentTestCase extends DrupalUnitTestCase {

Not OK. Calls into system_region_list(), and relies on the global $theme_key.

+++ b/core/modules/simpletest/tests/image.test
@@ -194,7 +194,7 @@ class ImageToolkitUnitTest extends ImageToolkitTestCase {
-class ImageToolkitGdTestCase extends DrupalWebTestCase {
+class ImageToolkitGdTestCase extends DrupalUnitTestCase {

Not OK. Calls into image_get_available_toolkits(), which invokes module hooks to return available image toolkits, which in turn means that it relies on the system environment/configuration.

+++ b/core/modules/simpletest/tests/xmlrpc.test
@@ -3,7 +3,7 @@
-class XMLRPCBasicTestCase extends DrupalWebTestCase {
+class XMLRPCBasicTestCase extends DrupalUnitTestCase {

Not OK. Performs a HTTP request to core/xmlrpc.php, which in turn invokes hook_xmlrpc() in all modules, and thus, relies on the system environment/configuration.

LSU_JBob’s picture

@sun when you mean 'Not OK' are you advising removal of that line? If so I can cut out those last 3 and re-roll.

jbrown’s picture

Yes - the changes than @sun marked as Not OK need to be removed from the patch.

LSU_JBob’s picture

Status: Needs work » Needs review
StatusFileSize
new1.37 KB

Cool, re-rolled!

Niklas Fiekas’s picture

Status: Needs review » Reviewed & tested by the community

Thank you.

Those tests are - like sun already stated - not dependent on configuration and environment, so yeah, that seams to be it. Though fewer conversions are left than I hoped for ;)

dries’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Good catch. Committed to 8.x.

Moving to 7.x for back-porting.

albert volkman’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.42 KB

D7 backport.

Niklas Fiekas’s picture

Status: Needs review » Reviewed & tested by the community

Thank you.

sun’s picture

Title: Improve test performance (and hence PIFR performance) by extending DrupalUnitTestCase where possible » Use DrupalUnitTestCase where possible

Shortening and clarifying issue, since every time I see this issue I'm thinking of something completely different.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 7.x. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -Performance, -Novice, -Needs backport to D7, -Testing system

Automatically closed -- issue fixed for 2 weeks with no activity.