This shows you the differences between two versions of the page.
|
poo-ca-cd:alte-resurse:junit-java [2021/10/16 13:36] radu_bogdan.pavel [Unit testing] |
poo-ca-cd:alte-resurse:junit-java [2021/11/24 00:52] (current) radu_bogdan.pavel [Unit testing] |
||
|---|---|---|---|
| Line 101: | Line 101: | ||
| import org.junit.jupiter.api.* | import org.junit.jupiter.api.* | ||
| - | public class Test { | + | public class GroupTest { |
| private Group group; | private Group group; | ||
| Line 111: | Line 111: | ||
| @Test | @Test | ||
| public void testNoStudentInGroup() { | public void testNoStudentInGroup() { | ||
| - | Assert.assertEquals(false, group.areStudentsInGroup()); | + | Assertions.assertEquals(false, group.areStudentsInGroup()); |
| } | } | ||
| Line 119: | Line 119: | ||
| group.addStudent(st); | group.addStudent(st); | ||
| - | Assert.assertTrue(group.getStudent("Elena").equals(st)); | + | Assertions.assertTrue(group.getStudent("Elena").equals(st)); |
| } | } | ||
| | | ||
| Line 132: | Line 132: | ||
| **Observaţii:** | **Observaţii:** | ||
| * fiecare metodă de test are adnotarea: ''@Test'' | * fiecare metodă de test are adnotarea: ''@Test'' | ||
| - | * metodele de **setUp** (având adnotarea: ''@Before'') şi **tearDown** (având adnotarea: ''@After'') se apelează înainte, respectiv după fiecare test. Se întrebuinţează pentru iniţializarea/eliberarea resurselor ce constituie mediul de testare, evitându-se totodată duplicarea codului şi respectându-se principiul de independenţă a testelor. Pentru exemplul dat ordinea este: | + | * metodele de **setUp** (având adnotarea: ''@BeforeEach'') şi **tearDown** (având adnotarea: ''@AfterEach'') se apelează înainte, respectiv după fiecare test. Se întrebuinţează pentru iniţializarea/eliberarea resurselor ce constituie mediul de testare, evitându-se totodată duplicarea codului şi respectându-se principiul de independenţă a testelor. Pentru exemplul dat ordinea este: |
| * ''@BeforEach setUp'' | * ''@BeforEach setUp'' | ||
| * ''@Test testNoStudentInGroup'' | * ''@Test testNoStudentInGroup'' | ||
| Line 155: | Line 155: | ||
| <note important> | <note important> | ||
| - | În cadrul laboratorului vom folosi framework-ul JUnit5 adăugând fişierele [[http://search.maven.org/remotecontent?filepath=junit/junit/4.12/junit-4.12.jar|junit.jar]] şi [[https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/hamcrest/hamcrest-all-1.3.jar|hamcrest-all-1.3.jar]] cu acesta la proiectele create. | + | Pentru a folosi framework-ul JUnit5, consultați tutorialul din [[poo-ca-cd:laboratoare:colectii|laboratorul 8]], aflat la secțiunea **Unit testing**. |
| - | + | ||
| - | Pentru a importa un //jar// într-un proiect din ''Eclipse'' parcurgeţi următorii paşi: //click dreapta proiect// -> //Build path// -> //Configure build path// -> //Libraries// -> //Add jars (Add external jars)//. | + | |
| </note> | </note> | ||
| Line 190: | Line 188: | ||
| * <html><a class="media mediafile mf_pdf" href="/poo/laboratoare/exceptii?do=export_pdf">PDF laborator</a></html> | * <html><a class="media mediafile mf_pdf" href="/poo/laboratoare/exceptii?do=export_pdf">PDF laborator</a></html> | ||
| - | * [[http://search.maven.org/remotecontent?filepath=junit/junit/4.12/junit-4.12.jar|Junit Download]] | ||
| - | * [[http://search.maven.org/remotecontent?filepath=org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar|Hamcrest Core]] | ||
| * {{:poo-ca-cd:alte-resurse:junit-java:skel.zip|Schelet}} | * {{:poo-ca-cd:alte-resurse:junit-java:skel.zip|Schelet}} | ||
| - | * {{:poo-ca-cd:alte-resurse:junit-java:sol.zip|Soluție}} | + | * {{:poo-ca-cd:alte-resurse:solutie-junit.zip|Solutie}} |
| ==== Referinţe ==== | ==== Referinţe ==== | ||