spln2016:diario7:diario
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| spln2016:diario7:diario [2016/04/13 12:52] – created ambs | spln2016:diario7:diario [2016/04/13 12:59] (current) – [Testes em Módulos Perl] ambs | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | Aula 11 de Abril de 2016 | + | ====== SPLN ====== |
| - | Maquina Virtual : http:// | + | ==== Diário de Bordo - Aula 7 - 2016-04-11 ==== |
| - | user: spln | pw: spln | + | |
| - | Apresentações dos trabalhos de grupo | + | * Maquina Virtual : http:// |
| + | * user: spln | pw: spln | ||
| - | Correr testes perl (tipo de output): output formato TAP {Test Anything Protocol} | + | ==== Sumário ==== |
| - | # | + | Apresentações dos trabalhos |
| - | file 00-load.t | + | |
| - | #comando para executar um teste (-T define o tipo de output) | + | |
| - | perl -T -Ilib t/00-load.t | + | |
| + | Testes em módulos Perl | ||
| - | #módulo para criação de testes | + | ==== Testes em Módulos Perl ==== |
| - | use Test::More; | + | |
| - | #Begin é um bloco de código que executa antes de qualquer outro no documento | + | Correr testes Perl (tipo de output): output formato TAP {Test Anything Protocol} |
| - | BEGIN { | + | |
| - | #numero de testes | + | São guardados em ficheiro de teste com extensão *.t |
| + | |||
| + | perl -T -Ilib t/ | ||
| + | |||
| + | Notas: | ||
| + | * -T usado para "Taint mode" (modo especialmente protegido do Perl) | ||
| + | * -Ilib usado para incluir módulos da pasta ' | ||
| + | |||
| + | módulo para criação de testes | ||
| + | |||
| + | use Test:: | ||
| + | |||
| + | Begin é um bloco de código que executa antes de qualquer outro na script | ||
| + | |||
| + | BEGIN { | ||
| + | # numero de testes | ||
| plan tests => 4; | plan tests => 4; | ||
| + | |||
| + | # teste 1: carregar o módulo com sucesso? | ||
| use_ok (' | use_ok (' | ||
| - | } | + | |
| - | my $table = Statistics: | + | |
| - | #ver se cria tabela vazia | + | Teste 2: ver se é criado um objeto |
| - | ok $table, " | + | |
| - | #= if ($table) {print "ok 2\n"} else {print "nok 2\n"} | + | |
| + | ok $table, " | ||
| + | # if ($table) {print "ok 2\n"} else {print "not ok 2\n"} | ||
| + | |||
| + | Teste 3: verificar tipo do objeto | ||
| + | |||
| + | is ref($table), | ||
| + | |||
| + | Teste 4: ver se a tabela tem a estrutura certa | ||
| + | |||
| + | is_deeply $table, { freqs => {} }, "tem estrutura certa"; | ||
| - | #verifica tipo | + | Teste 5: Ver se as palavras são adicionados com sucesso |
| - | is ref($table), | + | |
| - | #ver se a tabela é uma hash vazia | + | |
| - | # | + | ok exists($table->{freqs}{palavra}); |
| - | is_deeply | + | is $table->{freqs}{palavra}, 1; |
| + | Para evitar ter de mudar constantemente o número de testes planeados, é possível usar a função | ||
| - | $table-> | + | done_testing(); |
| - | ok exists($table-> | + | |
| - | is $table-> | + | |
| - | diag(" Testing Statistics:: | + | no final do ficheiro de testes |
| - | # | + | Outras formas de testar manualmente um ficheiro .t: |
| - | #testar manualmente: | + | |
| - | #prove t/ | + | |
| - | #prove -v t/ | + | |
spln2016/diario7/diario.1460551935.txt.gz · Last modified: 2016/04/13 12:52 by ambs