Extension:MWUnit/Debugging tests

From mediawiki.org
Jump to navigation Jump to search

When a test is run, the actual output that test generates is not visible. It is only visible whether or not the test passed or failed. This makes tests hard to debug.

Suppose the Loops extension is used to iteratively run an assertion a hundred times:

<testcase name="testFoobar" group="Foobar tests" context="canonical" covers="Foobar">
    {{#loop: $i
     | 0
     | 100
     | {{#assert_greater_than: $i | {{#expr: $i - {{Foobar}} }} }}
    }}
</testcase>

The test succeeds, but from the raw testcase it is not entirely clear why the test succeeded. It may very well be possible the #expr parser function just always returns "-1". To check whether the testcase is written properly, the parser function #var_dump can be used:

<testcase name="testFoobar" group="Foobar tests" context="canonical" covers="Foobar">
    {{#loop: $i
     | 0
     | 100
     | {{#assert_greater_than: $i | {{#expr: $i - {{Foobar}} }} }}
    }}

    {{#var_dump: {{Foobar}} }}
</testcase>

Now the following will be appended to the test result:

The test outputted the following:

int(10)

See also[edit]

Writing tests - Documentation on how to write tests