Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
simpletest.module
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
16 May 2009 at 20:17 UTC
Updated:
9 Jun 2009 at 17:00 UTC
Jump to comment: Most recent file
Some tests do not need a child Drupal to meddle with. Two samples included.
| Comment | File | Size | Author |
|---|---|---|---|
| #48 | drupal_unit_test_case.patch | 15.18 KB | chx |
| #47 | drupal_unit_test_case.patch | 15.4 KB | chx |
| #46 | drupal_unit_test_case.patch | 15.61 KB | chx |
| #45 | drupal_unit_test_case.patch | 15.78 KB | chx |
| #44 | drupal_unit_test_case.patch | 15.09 KB | chx |
Comments
Comment #1
chx commentedcatch asked for more documentation. My pleasure, sir.
Comment #3
chx commentedIf i clock my CPU enough to time this i get 4s vs 0s...
Comment #4
chx commentedI was careless in the condition and it failed when there were no modules to be installed.
Comment #5
dries commentedPersonally, I think it is non-trivial to figure out whether a test writes to the database. Even a simple test can call some functions that indirectly cause a database write operation; e.g. a function has a watchdog call.
How many tests would benefit from this? Right now, it is hard to know whether we would benefit from introducing a special case. I prefer not to introduce special cases unless it brings significant improvements. Any thoughts or estimates on that?
Another idea could be to make this automatic. Install a listener on mutator queries, and install a new copy of Drupal upon the first insert or update.
Comment #6
chx commentedSee above: if you want to run a smaller test or two only the difference is colossal. And while it might not be easy to figure out when to use this, it's optional and if you do not use it, no harm done. I do not really think we want to mess with DBTNG just to allow such a simple feature.
Comment #7
catchAs long as this is documented clearly enough that it only gets used when it should be I think we're fine - and I think chx's comments are sufficient for that. It takes so long to run tests right now (I haven't run the full test suite locally for more than a month), that anything we can do to improve it is great.
Comment #8
cwgordon7 commentedI think it would be cleaner to use this as an opportunity to separate DrupalWebTestCase into a DrupalWebTestCase and a DrupalUnitTestCase, both of which extend a base class (DrupalTestCase), which contains the methods common to both classes.
Another thought, why not just disconnect the database entirely for unit tests? Ideally, unit tests should not depend on anything in the database in order to function properly.
Comment #9
chx commentedDisconnecting the db was my idea :) and can be achieved imo by changing the global $database and running a db_set_active to a connection that is guaranteed not to work.
Comment #10
chx commentedHere we come. I only mess with the db_prefix -- its a time honored way to make sure the DB is not available. If a test like this tries to access the database it will get some nice table does not exist exceptions from DBTNG. The patch is mostly copypaste.
Comment #11
damien tournoud commentedI don't really see the use of that, it's simple enough just to override setUp() in your class if you are *really*, *really* confident that you don't need the database, nor to touch the registry or anything.
Comment #12
chx commentedDamien, how many tests should I convert so that you see that this is a common enough case?
Comment #13
damien tournoud commented#10 and #12 makes sense to me. But this will need a lot of documentation, in order to make the constraints cristal clear.
Comment #14
chx commentedMight be a bit terse but care to suggest more comments, then? To me it sounds like the restrictions are clearly states.
Comment #15
chx commentedAlso note that my added safety check in simpletest.module needs to be either removed or fixed -- though the tests are green there are only 2K+ instead of the 10K+ as there should be. As we want to write more comments anyways, I keep this at CNR.
Comment #16
dries commentedThe last version of this patch makes for a much better design -- it is certainly less of a hack now. Like it much better.
A number of functions only make sense for DrupalWebTestCase, and not for DrupalUnitTestCase. For example, drupalCreateUser(). Should we move these from the base class, DrupalTestCase, to DrupalWebTestCase?
It might also make sense to rename drupal_web_test_case.php -- but we can do that in a quick follow-up patch.
Comment #17
chx commentedDries, yes we want to rename. I do not know what functiions are you talking of. The base class contains: __construct, assert, getAssertionCall, assertTrue, assertFalse, assertNull, assertNotNull, assertEqual, assertNotEqual, assertIdentical, assertNotIdentical, pass, fail, error, run, errorHandler, exceptionHandler, randomString, randomName and nothing else. These are IMO necessary in the base and nothing else is. drupalCreateUser have not been moved.
Comment #18
dries commentedchx, you're right! Let's keep this moving forward then. :)
Comment #19
damien tournoud commentedTo clarifiy #13: we need to make clear that you cannot use any function that directly or indirectly touches the database. That includes watchdog(), drupal_function_exists(), module_invoke_all(), module_implements(), t() if locale is enabled, etc.
Comment #20
boombatower commentedHey! DrupalUnitTestCase is back!??! woha...
Seems to have the same concept as before and would finally make DrupalWebTestCase name useful again.
Comment #21
chx commentedComment #22
chx commentedThe above was Damien's comment enrolled into the Doxygen this one is whitespace fixes.
Comment #23
damien tournoud commentedThis cannot flight as-is: assertTrue(), assertFalse() and assertNull all can call t(), if no explicit message is passed to them. We either need to make t() work in the unit test environment (for example by removing the locale module from module_list()), or we need to remove those calls.
Comment #24
chx commentedNot hard to do.
Comment #25
chx commentedMore comments and a bit nicer code.
Comment #26
damien tournoud commentedDear testbot, please RTBC this for me if it comes back clean.
Comment #27
chx commentedWithout the kitten-killing , unnecessary change in simpletest.module
Comment #28
dries commentedI'm worried about the t() hack that we just added. It sounds like it could be the first hack of many hacks ...
If we want to speed up testing, it might be better to remove
t()functions fromassertXXX().I'd prefer to keep this hack-free ...
Comment #29
dries commentedJust to clarify -- I'd love to make the tests faster, but I don't want to obsess about it. Clean code is more important than fast tests, so I want us to optimize for clean code here.
Comment #30
chx commentedI let others figure out why there are so few tests after the patch and either convince you to that fast tests are necessary or move t() to the result display. I am done here.
Comment #31
dries commentedI don't understand this part of your comment: "I let others figure out why there are so few tests after the patch". Please be a bit more detailed. Thanks!
Comment #32
damien tournoud commented@Dries:
That's not a lot of assertions ;)
Comment #33
catchWe should kill t() from assertions anyway, I can't imagine anyone ever wanting to translate them, and will they fill up the {locale} table?
Comment #34
cwgordon7 commentedHow would Drupal know what language to translate it into if we're on a test database? Using t() should only be a problem for unit test assertions.
It also looks like it is not running tests outside of the simpletest/tests folder, though I have no idea why.
Comment #35
boombatower commented@chx: The reason the tests don't run properly is that assert() is a private method and cannot be declared that way when used by subclasses.
Comment #36
chx commentedThat needs to protected then.
Comment #37
boombatower commented@chx: indeed, was responding per #30.
It seems odd to include DrupalTestCase, DrupalUnitTestCase, and DrupalWebTestCase in a file named drupal_web_test_case.php
Perhaps drupal_test_case.inc?
Comment #38
chx commentedAs noted earlier we want to rename this file later.
Comment #39
dries commentedIf we rename the file (later!), let's also get rid of 'drupal_'. At some point, we should rename SimpleTest to Test or Testing, IMO.
I agree that we should probably nuke the t() functions from the assertions instead.
Comment #40
chx commentedNow that locale disable is in, we can do more.
Comment #42
chx commentedI am down to 4 fails with this code. The problem is that despite my efforts,
these still come from DWTC instead of the stub test they should.
Edit: the dump is from simpletest.test assertAssertion.
Comment #44
chx commentedThis was not easy. PHP below 5.3 does not see private properties with property_exists. It does see methods with method_exists but even if a method is defined as private it exists in the children. But! constants to the rescue.
Comment #45
chx commentedAdded the design motivation in the doxygen. No code change.
Comment #46
chx commentedRemoved some comment duplication.
Comment #47
chx commentedChanged to a property per DamZ's suggestion. Seems less hackish. Also, we could evaluate our tests to see which utility classes needs to be skipped, it's just a matter of copy-pasting the constructor around.
Comment #48
chx commentedMore code cleanup thanks to DamZ. This is getting close.
Comment #49
damien tournoud commentedIt looks good, and it has been green lighted by the bot, let's get this in ;)
Comment #50
dries commentedWill commit this tomorrow morning -- feel free to start updating more tests in the mean time. We might discover new things as we do so.
Comment #51
dries commentedCommitted. Thanks!
Comment #52
boombatower commentedSince this re-introduced the DrupalUnitTest case, #266555: Rename DrupalWebTestCase to DrupalTestCase? is no longer useful.