Semantic MediaWiki and related extensions
README

Tests are commonly divided into a manual (without using any tool or automated script) and an automated scripted test approach.

Manual testing

If you want to run some manual tests (either as scripted or exploratory test procedure) then you just have to:

  1. Download a related branch using 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.
  2. Run composer dump-autoload to ensure that all registered classes are correctly initialized before starting any test procedure.

Automated testing (PHPUnit)

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.

Running tests

  1. Verify that PHUnit is installed in myMediawikiFolder/vendor/phpunit. In case it is not installed, use composer require phpunit/phpunit:~6.5 --update-with-dependencies to add the package
  2. Verify that your MediaWiki installation comes with its test files and folders (e.g. /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.
  3. Run 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 tests

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

Unit tests

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.

Integration tests

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:

The Integration directory is expected to host tests that target the validation of reciprocity with MediaWiki and/or other services such as:

Some details about the integration test environment can be found https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/tests/travis/README.md "here".

JSONScript

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.

Benchmark tests

For details, please have a look at the https://github.com/SemanticMediaWiki/SemanticMediaWiki/tree/master/tests/phpunit/Benchmark/README.md "benchmark guide" document.

JavaScript (QUnit)

Running qunit tests in connection with MediaWiki requires to execute Special:JavaScriptTest. QUnit tests are currently not executed on Travis (see #136).

Miscellaneous


About | General disclaimer | Privacy policy