Projet

Général

Profil

TestsCodeBonnesPratiques » Historique » Version 1

Gwenael Remond, 18/01/2013 09:16

1 1 Gwenael Remond
h1. TestsCodeBonnesPratiques
2 1 Gwenael Remond
3 1 Gwenael Remond
* créer un dossier de tests dans le projet (typiquement <code>tests</code>)
4 1 Gwenael Remond
* l'écriture des tests se fait avec l'outil <code>py.test</code> (http://pytest.org/latest/)
5 1 Gwenael Remond
* **attention** : ces tests seront pris en compte lors de la compilation d'un paquet (en d'autres termes, si les tests ne passent pas, le paquet ne sera pas compilé) 
6 1 Gwenael Remond
* pour dissocier la notion de test unitaire de la notion de test fonctionnel, il importe de "tagger" le test avec le mot clef correspondant, à savoir : 
7 1 Gwenael Remond
8 1 Gwenael Remond
pour un test unitaire : 
9 1 Gwenael Remond
<pre>
10 1 Gwenael Remond
py.test.mark.unitary 
11 1 Gwenael Remond
</pre>
12 1 Gwenael Remond
13 1 Gwenael Remond
pour un test fonctionnel : 
14 1 Gwenael Remond
<pre>
15 1 Gwenael Remond
py.test.mark.functional
16 1 Gwenael Remond
</pre>
17 1 Gwenael Remond
18 1 Gwenael Remond
à utiliser en tant que décorateur, par exemple : 
19 1 Gwenael Remond
20 1 Gwenael Remond
<pre>
21 1 Gwenael Remond
@py.test.mark.unitary 
22 1 Gwenael Remond
def mon_test():
23 1 Gwenael Remond
    assert ma_fonction(2) == 3
24 1 Gwenael Remond
</pre>