Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
ens:cvda2016:tpachille [2016/03/31 23:27] admin Cordier Amelie () [La contribution essentielle de Tari.] |
ens:cvda2016:tpachille [2016/05/10 10:39] (Version actuelle) admin Cordier Amelie () [Dernier tour de piste.] |
||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Introduction aux tests unitaires - Le talent d' | ====== Introduction aux tests unitaires - Le talent d' | ||
| + | |||
| + | <WRAP center round tip 60%> | ||
| + | À l' | ||
| + | |||
| + | </ | ||
| + | |||
| Achille, gérant d'une grande société de divertissement a inventé un système de résolution de problème révolutionnaire et vous en confie l' | Achille, gérant d'une grande société de divertissement a inventé un système de résolution de problème révolutionnaire et vous en confie l' | ||
| Ligne 60: | Ligne 66: | ||
| + | ===== Exemples de code ===== | ||
| + | |||
| + | <file java Seau.java> | ||
| + | /* | ||
| + | * To change this license header, choose License Headers in Project Properties. | ||
| + | * To change this template file, choose Tools | Templates | ||
| + | * and open the template in the editor. | ||
| + | */ | ||
| + | package testsunitairesg1; | ||
| + | |||
| + | import java.util.ArrayList; | ||
| + | |||
| + | /** | ||
| + | * | ||
| + | * @author amelie.cordier | ||
| + | */ | ||
| + | public class Seau { | ||
| + | | ||
| + | ArrayList seau; | ||
| + | | ||
| + | public Seau(){ | ||
| + | seau = new ArrayList(); | ||
| + | } | ||
| + | | ||
| + | public Seau(String truc1, String truc2){ | ||
| + | seau = new ArrayList(); | ||
| + | seau.add(truc1); | ||
| + | seau.add(truc2); | ||
| + | } | ||
| + | | ||
| + | public void ajouter(String chose){ | ||
| + | seau.add(chose); | ||
| + | } | ||
| + | | ||
| + | public void afficher(){ | ||
| + | System.out.println(seau); | ||
| + | } | ||
| + | | ||
| + | public int nbElements(){ | ||
| + | return seau.size(); | ||
| + | } | ||
| + | | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | <file java SeauTest.java> | ||
| + | /* | ||
| + | * To change this license header, choose License Headers in Project Properties. | ||
| + | * To change this template file, choose Tools | Templates | ||
| + | * and open the template in the editor. | ||
| + | */ | ||
| + | package testsunitairesg1; | ||
| + | |||
| + | import org.junit.Test; | ||
| + | import static org.junit.Assert.*; | ||
| + | |||
| + | /** | ||
| + | * | ||
| + | * @author amelie.cordier | ||
| + | */ | ||
| + | public class SeauTest { | ||
| + | | ||
| + | public SeauTest() { | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Vérifie qu'un seau vide est bien vide | ||
| + | */ | ||
| + | @Test | ||
| + | public void testSeauVide() { | ||
| + | Seau monseau = new Seau(); | ||
| + | assertEquals(0, | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Vérifie que l' | ||
| + | */ | ||
| + | @Test | ||
| + | public void testAjouterASeauVide() { | ||
| + | Seau monseau = new Seau(); | ||
| + | monseau.ajouter(" | ||
| + | assertEquals(1, | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Vérifie que l' | ||
| + | */ | ||
| + | @Test | ||
| + | public void testAjouterASeau2Elts() { | ||
| + | Seau monseau = new Seau(" | ||
| + | monseau.ajouter(" | ||
| + | assertEquals(3, | ||
| + | } | ||
| + | /** | ||
| + | * (redondant) vérifie le bon fonctionnement de nbElements | ||
| + | */ | ||
| + | @Test | ||
| + | public void testNbElements() { | ||
| + | Seau monseau = new Seau(" | ||
| + | assertEquals(2, | ||
| + | } | ||
| + | | ||
| + | } | ||
| + | |||
| + | </ | ||