Your SlideShare is downloading. ×
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply



Published on

1 Like
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Manajemen dan Kualitas Perangkat Lunak IKP321 Unit Testing
  • 2. Unit Perangkat Lunak Code Documentation Procedure Data Satuan terkecil Code Unit Method atau Function atau Procedure
  • 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. Rehat Sejenak: JUnit Package untuk menjalankan Unit Testing di Java Dapat diunduh dari 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. 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. Kompilasi Class Test Case CLASSPATH sudah diset javac CLASSPATH belum diset javac -cp /usr/share/java/junit-4.10.jar javac -cp C:jarfilesjunit-4.10.jar Jalankan Test Case java junit.textui.TestRunner MaxThreeTest java junit.swingui.TestRunner MaxThreeTest java org.junit.runner.JUnitCore MaxThreeTest
  • 7. Kompilasi Class Test Case.ETime: 0.043There was 1 error:1) testSimple(MaxThreeTest)java.lang.NoClassDefFoundError: MaxThree at MaxThreeTest.testSimple( at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) atsun.reflect.NativeMethodAccessorImpl.invoke( atsun.reflect.DelegatingMethodAccessorImpl.invoke( by: java.lang.ClassNotFoundException: MaxThree at$ at Method) at at java.lang.ClassLoader.loadClass( at sun.misc.Launcher$AppClassLoader.loadClass( at java.lang.ClassLoader.loadClass( ... 16 moreFAILURES!!!Tests run: 1, Failures: 0, Errors: 1
  • 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. Implementasi Class if (a >= b) { max = a; } else { max = b; } if (c >= max) { max = c; } return max; }}
  • 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. JUnit dan Eclipse Eclipse IDE for Java Developers  downloads/ Unduh, Pasang, dan Jalankan Buat Java Project yang baru
  • 12. JUnit dan Eclipse
  • 13. JUnit dan Eclipse Klik-kanan src, pilih New, pilih Class Tuliskan nama class  MyClass
  • 14. JUnit dan Eclipse
  • 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. JUnit dan Eclipse Pilih nama method yang perlu dibuat Test Case- nya
  • 17. JUnit dan Eclipse Tambahkan class JUnit ke dalam path Project
  • 18. JUnit dan Eclipse
  • 19. JUnit dan Eclipse Klik-kanan pada Class Test Case, Pilih Run As, Pilih JUnit test
  • 20. JUnit dan Eclipse
  • 21. Pustaka