• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
778
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
42
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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 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. 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 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. 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. 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  http://www.eclipse.org/ 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 http://www.vogella.de/articles/JUnit/article.html starship.python.net/~tbryan/UnitTestTalk/index.html tjerdastangkas.blogspot.com/search/label/ikp321