0
Manajemen dan Kualitas Perangkat Lunak              IKP321             Unit Testing
Unit   Perangkat Lunak   Code   Documentation   Procedure   Data   Satuan terkecil Code   Unit   Method atau Funct...
Unit Test   a piece of code   written by a developer   executes a specific functionality in the code under test   Unit...
Rehat Sejenak: JUnit   Package untuk menjalankan Unit Testing di Java   Dapat diunduh dari    https://github.com/KentBe...
Deklarasi Class Test Caseimport junit.framework.*;public class MaxThreeTest extends TestCase {    public MaxThreeTest(Stri...
Kompilasi Class Test Case   CLASSPATH sudah diset   javac MaxThreeTest.java   CLASSPATH belum diset   javac -cp /usr/s...
Kompilasi Class Test Case.ETime: 0.043There was 1 error:1) testSimple(MaxThreeTest)java.lang.NoClassDefFoundError: MaxThre...
Implementasi Classpublic class MaxThree {  /**   * Return the largest element from 3 integers.   *   * @param a,b,c Three ...
Implementasi Class        if (a >= b) {            max = a;        } else {            max = b;        }        if (c >= m...
●Jalankan Test Case   java junit.textui.TestRunner MaxThreeTest   java junit.swingui.TestRunner MaxThreeTest   java org...
JUnit dan Eclipse   Eclipse IDE for Java    Developers        http://www.eclipse.org/         downloads/   Unduh, Pasan...
JUnit dan Eclipse
JUnit dan Eclipse   Klik-kanan src, pilih New,    pilih Class   Tuliskan nama class        MyClass
JUnit dan Eclipse
JUnit dan Eclipse   Klik-kanan pada Class    yang baru dibuat   Pilih New, pilih Junit Test    Case   Pilih opsi "New J...
JUnit dan Eclipse   Pilih nama method yang    perlu dibuat Test Case-    nya
JUnit dan Eclipse   Tambahkan class JUnit ke    dalam path Project
JUnit dan Eclipse
JUnit dan Eclipse   Klik-kanan pada Class    Test Case,   Pilih Run As,   Pilih JUnit test
JUnit dan Eclipse
Pustaka   http://www.vogella.de/articles/JUnit/article.html   starship.python.net/~tbryan/UnitTestTalk/index.html   tje...
Upcoming SlideShare
Loading in...5
×

ikp321-04

848

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
848
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
45
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "ikp321-04"

  1. 1. Manajemen dan Kualitas Perangkat Lunak IKP321 Unit Testing
  2. 2. Unit Perangkat Lunak Code Documentation Procedure Data Satuan terkecil Code Unit Method atau Function atau Procedure
  3. 3. Unit Test a piece of code written by a developer executes a specific functionality in the code under test Unit tests ensure that code is working as intended and validate that this is still the case after code changes. Menguji apakah Unit sudah berfungsi sebagaimana yang diharapkan (as expected) Menguji Unit secara independen, tanpa bergantung pada hasil komputasi Unit lain
  4. 4. Rehat Sejenak: JUnit Package untuk menjalankan Unit Testing di Java Dapat diunduh dari https://github.com/KentBeck/junit/downloads Jar file junit-4.10.jar Simpan di folder tertentu C:jarfilesjunit-4.10.jar /usr/share/java/junit-4.10.jar Update CLASSPATH environment variable Set CLASSPATH=.;C:jarfilesjunit-4.10.jar Export CLASSPATH=.:/usr/share/java/junit-4.10.jar
  5. 5. Deklarasi Class Test Caseimport junit.framework.*;public class MaxThreeTest extends TestCase { public MaxThreeTest(String name) { super(name); } @Test public void testSimple() { assertEquals(9, MaxThree.largest(7, 8, 9)); }}
  6. 6. Kompilasi Class Test Case CLASSPATH sudah diset javac MaxThreeTest.java CLASSPATH belum diset javac -cp /usr/share/java/junit-4.10.jar MaxThreeTest.java javac -cp C:jarfilesjunit-4.10.jar MaxThreeTest.java Jalankan Test Case java junit.textui.TestRunner MaxThreeTest java junit.swingui.TestRunner MaxThreeTest java org.junit.runner.JUnitCore MaxThreeTest
  7. 7. Kompilasi Class Test Case.ETime: 0.043There was 1 error:1) testSimple(MaxThreeTest)java.lang.NoClassDefFoundError: MaxThree at MaxThreeTest.testSimple(MaxThreeTest.java:13) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)Caused by: java.lang.ClassNotFoundException: MaxThree at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 16 moreFAILURES!!!Tests run: 1, Failures: 0, Errors: 1
  8. 8. Implementasi Classpublic class MaxThree { /** * Return the largest element from 3 integers. * * @param a,b,c Three integers * @return The largest number between inputs. */ public static int largest(int a, int b, int c) { int max;
  9. 9. Implementasi Class if (a >= b) { max = a; } else { max = b; } if (c >= max) { max = c; } return max; }}
  10. 10. ●Jalankan Test Case java junit.textui.TestRunner MaxThreeTest java junit.swingui.TestRunner MaxThreeTest java org.junit.runner.JUnitCore MaxThreeTest Hasil JUnit version 4.10 . Time: 0.005 OK (1 test)
  11. 11. JUnit dan Eclipse Eclipse IDE for Java Developers  http://www.eclipse.org/ downloads/ Unduh, Pasang, dan Jalankan Buat Java Project yang baru
  12. 12. JUnit dan Eclipse
  13. 13. JUnit dan Eclipse Klik-kanan src, pilih New, pilih Class Tuliskan nama class  MyClass
  14. 14. JUnit dan Eclipse
  15. 15. JUnit dan Eclipse Klik-kanan pada Class yang baru dibuat Pilih New, pilih Junit Test Case Pilih opsi "New JUnit 4 test" Ubah nama folder ke folder "test"
  16. 16. JUnit dan Eclipse Pilih nama method yang perlu dibuat Test Case- nya
  17. 17. JUnit dan Eclipse Tambahkan class JUnit ke dalam path Project
  18. 18. JUnit dan Eclipse
  19. 19. JUnit dan Eclipse Klik-kanan pada Class Test Case, Pilih Run As, Pilih JUnit test
  20. 20. JUnit dan Eclipse
  21. 21. Pustaka http://www.vogella.de/articles/JUnit/article.html starship.python.net/~tbryan/UnitTestTalk/index.html tjerdastangkas.blogspot.com/search/label/ikp321
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×