Semantic MediaWiki and related extensions
|
Tests are commonly divided into a manual (without using any tool or automated script) and an automated scripted test approach.
If you want to run some manual tests (either as scripted or exploratory test procedure) then you just have to:
composer require "mediawiki/semantic-media-wiki:dev-foo
(where foo
refers to the branch name) or in case you want to test the current master, use @dev
or dev-master
as version together with the minimum-stability: dev
flag so that the branch/master can be fetched without any stability limitations.composer dump-autoload
to ensure that all registered classes are correctly initialized before starting any test procedure.For the automated approach, Semantic MediaWiki relies on PHPUnit as scripted testing methodology. Scripted tests are used to verify that an expected behaviour occurs for codified requirements on the given conditions.
myMediawikiFolder/vendor/phpunit
. In case it is not installed, use composer require phpunit/phpunit:~6.5 --update-with-dependencies
to add the package/myMediawikiFolder/tests
) in order for Semantic MediaWiki to have access to registered MW-core classes. If the tests
folder is missing then you may follow the release source to download the missing files.composer phpunit
from the Semantic MediaWiki base directory (e.g. myMediawikiFolder/extensions/SemanticMediaWiki
) using a standard command line tool which should output something like:$ composer phpunit
Using PHP 7.2.30
Semantic MediaWiki: 3.2.0-alpha, git: abc234b SMWSQLStore (postgres:9.5.10)
MediaWiki: 1.31.7, git: 42e0b35 (refs/heads/REL1_31) Extension vendor autoloader
Site language: en Execution time: 2020-04-25 06:53
Debug logs: Disabled Xdebug: Disabled (or not installed)
Intl/ICU: 1.1.0 / 52.1 PCRE: 8.41 2017-07-05
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
Runtime: PHP 7.2.30 Configuration: /home/travis/build/SemanticMediaWiki/mw/extensions/SemanticMediaWiki/phpunit.xml.dist
............................................................. 61 / 8526 ( 0%) ............................................................. 122 / 8526 ( 1%)
Information about PHPUnit in connection with MediaWiki can be found at smw.org and mediawiki.org.
Writing meaningful tests isn't difficult but requires some diligence on how to setup a test and its environment. One simple rule is to avoid the use of hidden expectations or inheritance as remedy for the "less code is good code" aesthetics. Allow the code to be readable and if possible follow the arrange, act, assert pattern.
For a short introduction on "How to write a test for Semantic MediaWiki", have a look at this video.
/tests ├─ /phpunit │ ├─ Benchmark │ ├─ Fixtures │ ├─ Integration │ │ ├─ ... │ │ └─ JSONScript │ ├─ Structure │ └─ Unit │ └─ /qunit
Benchmark
contains collections of tests running benchmarksFixtures
contains fixed data and schemataIntegration
contains tests classified as testing the integration with MediaWiki, rely on an active DB connection, or connect to any other external serviceStructure
contains tests that verify some structural components, or not directly test a specific integration with Semantic MediaWiki or MediaWikiUnit
contains unit tests (those tests should not rely on an enabled MediaWiki or DB connection)The use of MediaWikiTestCase
is discouraged (as its binds tests and the test environment to MediaWiki) and it is best to rely on PHPUnit_Framework_TestCase
and where a MW database connection is required, use the MwDBaseUnitTestCase
instead.
QueryPrinterTestCase
base class for all query and result printersSpecialPageTestCase
derives from SemanticMediaWikiTestCase
Integration tests are vital to confirm the behaviour of a component from an integrative perspective that occurs through an interplay with its surroundings.
Those tests don't replace unit tests, they complement them to verify that an expected outcome does actually occur in combination with MediaWiki and other services.
Integration tests can help reduce the recurrence of regressions or bugs, given that a developers follows a simple process:
JSON
test and have it failThe Integration
directory is expected to host tests that target the validation of reciprocity with MediaWiki and/or other services such as:
SPARQLStore
)SESP
, SBL
etc.)Some details about the integration test environment can be found https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/tests/travis/README.md "here".
One best practice in Semantic MediaWiki is to write integration tests as pseudo https://github.com/SemanticMediaWiki/SemanticMediaWiki/tree/master/tests/phpunit/Integration/JSONScript/README.md "`JSONScript`" to allow non-developers to review and understand the setup and requirements of its test scenarios.
The JSON
format was introduced as abstraction layer to lower the barrier of understanding of what is being tested by using the wikitext markup to help design test cases quicker without the need to learn how PHPUnit
or internal MediaWiki
objects work.
For details, please have a look at the https://github.com/SemanticMediaWiki/SemanticMediaWiki/tree/master/tests/phpunit/Benchmark/README.md "benchmark guide" document.
Running qunit tests in connection with MediaWiki requires to execute Special:JavaScriptTest. QUnit tests are currently not executed on Travis (see #136).