Jump to content

Topic on Manual talk:JavaScript unit testing

Naming of test suite files

4
Krinkle (talkcontribs)

Brion added the following:

Test files often have the same name as the files they are testing, eg 'mediawiki.js' or 'jquery.colorUtil.js'. This makes code maintenance more difficult because bare filenames are often shown when navigating or working with code. Consider using the word 'test' visibly in the filename.

The reason I made it like that is twofold:

  1. Because it makes lazy comparison of directories easy ( glob() the dirs and loop through to detect modules without a test suite[1])
  2. Because we do the same in the PHP Unit framework testing.

I dont have any personal preference, if you think it's better, go ahead and make the change. Please ping me about/when one would commit this, so I can stand by and make the neccecary changes in the configuration of our TestSwarm (since the function that scans the svn directory for modules would have to strip the '.test' suffix when filtering the modules that are going to be distributed, because the module() call doesn't contain ".test", example).

  1. ā†‘ ofcourse adding a concatenation with ".test" in the target of the comparison isn't complicated, but it's one extra difference that has to be accounted for everywhere.
Brooke Vibber (talkcontribs)

Almost everything in tests/phpunit/includes is named with a 'Test.php' suffix; just yesterday I spent plenty of time fiddling with Block.php (Block class) and BlockTest.php (Block's test class), which was very pleasant to work with. It seems that most of the unit test files are similarly named: 'GlobalTest', 'ExternalStoreTest', 'HttpTest', 'MessageTest', 'MWNamespaceTest', 'SanitizerTest', 'RevisionTest', 'TitleTest', 'UploadTest', 'SearchDbTest', 'SearchEngineTest', 'SearchUpdateTest', 'DatabaseSqliteTest', 'DatabaseTest', 'ApiBlockTest', 'ApiWatchTest', 'ApiUploadTest', etc.

I would have been surprised and annoyed if the test class had been in another Block.php, and it would have made my life harder switching between a "Block.php" tab and another "Block.php" tab in my editor, trying to keep them straight. Yes the paths are different -- paths that are rarely shown in key parts of a programming editor's UI... When I encounter files that are confusingly named, I immediately want to change them to match our regular convention: with 'test' in the name.

Directory comparison, if that's something that's going to be done frequently, should probably be scripted up so people don't have to manually construct a command line every time -- even the simple case of matching names is not necessarily trivial.

Krinkle (talkcontribs)

In that case I blame the documentation on Manual:PHP unit testing:

The unit tests are located in the tests/phpunit directory Tests are organized into a directory structure that matches the directory structure of the code that they are testing. For example: The unit tests for file includes/IP.php can be found in tests/phpunit/includes/IP.php.

ā€“ oldid 405067 / edit

Thanks, I'll make the switch later tonight.

Krinkle (talkcontribs)

Looks like the current script is kinda hardcoded to not allow this. Rather than changing everything in a hurry I suggest postponing this to July (which, when all is good, is when I'm in SF). Then we'll be finishing up TestSwarm to move to a WMF host. Then in a bit of a rewrite we'll take this into account.

Reply to "Naming of test suite files"