Wikipedia:Lua/Modul/UnitTests/en

Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 25. Februar 2013 um 05:07 Uhr durch Dcoetzee (Diskussion | Beiträge) (Created page with 'UnitTests provides a unit test facility that can be used by other scripts using '''require'''. See Wikipedia:Lua#Unit_testing for details. Following is a sam...'). Sie kann sich erheblich von der aktuellen Version unterscheiden.
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

UnitTests provides a unit test facility that can be used by other scripts using require. See Wikipedia:Lua#Unit_testing for details. Following is a sample from Module:Bananas/tests:

-- Unit tests for [[Module:Bananas]]. Click talk page to run tests.
local p = require('Module:UnitTests')
 
function p:test_hello()
    self:preprocess_equals('{{#invoke:Bananas | hello}}', 'Hello, world!')
end
 
return p

The talk page Module talk:Bananas/tests executes it with {{#invoke: Bananas/tests | run_tests}}. Test methods like test_hello above must begin with "test".

Methods

  • preprocess_equals(text, expected): Gives a piece of wikitext to preprocess and an expected resulting value. Scripts and templates can be invoked in the same manner they would be in a page.
    self:preprocess_equals('{{#invoke:Bananas | hello}}', 'Hello, world!')
  • preprocess_equals_preprocess(text, expected): Gives two pieces of wikitext to preprocess and determines if they produce the same value. Useful for comparing scripts to existing templates.
    self:preprocess_equals_preprocess('{{#invoke:Bananas | hello}}', '{{Hello}}')