| Vorlagenprogrammierung | Diskussionen | Lua | Unterseiten | |||
| Modul | Deutsch | English
|
Modul: | Dokumentation | ||
UnitTests provides a unit test facility that can be used by other scripts using require().
Following is a sample from Module:Hello/test:
-- Unit tests for [[Module:Hello]]. Click test page to run tests.
local p = require('Module:UnitTests')
function p:test_hello()
self:preprocess_equals('{{#invoke:Hello | hello}}', 'Hello, world!')
end
return p
The test page Wikipedia:Lua/Modul/UnitTests/test executes it with:
{{#invoke: Bananas/test | run_tests}}
Test methods like test_hello above must begin with "test".
run_tests(differs_at) {{#invoke:Hello/test|run_tests}}
preprocess_equals(text, expected) self:preprocess_equals('{{#invoke:Hello | hello}}', 'Hello, world!')
preprocess_equals_many(prefix, suffix, cases) self:preprocess_equals_many('{{#invoke:DemoArgs | add |', '}}', {
{'2|3', '5'},
{'-2|2', '0'},
})
preprocess_equals_preprocess(text, expected) self:preprocess_equals_preprocess('{{#invoke:Hello | hello}}', '{{Hello}}')
preprocess_equals_preprocess_many(prefix, suffix, cases) self:preprocess_equals_preprocess_many('{{#invoke:Foo | spellnum |', '}}', '{{spellnum', '}}', {
{'2'}, -- equivalent to {'2','2'},
{'-2', '-2.0'},
})
equals(name, actual, expected) self:equals('Simple addition', 2 + 2, 4)
equals_deep(name, actual, expected) self:equals_deep('Table comparison', createRange(1,3), {1,2,3})
en:Module:UnitTests 2013-05-18
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.