SlideServe
Menu
Préférences
© SlideServe · v2026

JUNIT in Eclipse

cerise avatar
11 diapositives · 311 Views · Oct 21, 2014

JUNIT in Eclipse. Pepper Credit to Eclipse Documentation http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2FgettingStarted%2Fqs-junit.htm. Purpose. Create test case classes to test individual classes or small groups

JUNIT in Eclipse - slide 1
01 / 11JUNIT in Eclipse
1 / 17

Télécharger la présentation

JUNIT in Eclipse
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. JUNIT in Eclipse Pepper Credit to Eclipse Documentation http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2FgettingStarted%2Fqs-junit.htm

  2. Purpose • Create test case classes to test individual classes or small groups • Easy to hook test classes to the classes being tested • Test building tools inside Junit class • Easy to rerun one set of tests or all tests in the entire system. • Easy to supress tests in production

  3. Startup • Create a project if you do not have one (file -> New -> Project) • Create a folder for your test cases (optional) • Create a test case for a class you intend to write (file -> new -> Junit Test Case) • Choose the type (new junit4 test) and name your test class • You can indicate the name of the class being tested, but only after it is created

  4. Test Case Creation Screen

  5. How to Create a Test Method • Type @Test to override the test method • Type test method header -> public void test2() • Code the test to just invoke the fail method public void testFailure() throws Exception {    fail();}

  6. Running a test method • Hit the run button. • Or Run as -> Junit test on project or class • Junit Test runs • See results in JUnitView • Failure tab • Tab for all tests as a tree • * = changed code after running test

  7. Test Result Checking http://www.vogella.com/tutorials/JUnit/article.html • assertEquals() : object comparison using equals method • assertTrue() / assertFalse() : compare to boolean value • assertNull() / assertNotNull() : is the variable null • assertSame() / assertNotSame(): reference same object address • assertThat - uses matcher

  8. Let's Try • Write a simple class to be tested: package testProject; public class aprogram { int x = 1; public intmyfun (int y) { x = x + 1; return x; } }

  9. Now code a few tests package JUnitTest; import static org.junit.Assert.*; import org.junit.Test; import testProject.aprogram; public class TestFailure { @Test public void test1() { aprogram a = new aprogram(); aprogram b = new aprogram(); assertTrue( b.myfun(3) == 2 ); assertTrue( a.myfun(3) == 3 ); } @Test public void test2() { //fail("Not yet implemented"); aprogram a = new aprogram(); aprogram b = new aprogram(); assertTrue( b.myfun(3) == 4 ); //assertTrue( a.myfun(3) == 1 ); } }

  10. Run the Tests • See how it points to problem test • See how one failure in a test class stops the running of the next one • Make both succeed • Make both fail

  11. Create a Test Suite • File -> New -> Java -> Junit -> Junit Test Suite • Name the suite (AllTests) • Select test classes to run