ikp321-04
Upcoming SlideShare
Loading in...5
×
 

ikp321-04

on

  • 1,030 views

 

Statistics

Views

Total Views
1,030
Views on SlideShare
1,030
Embed Views
0

Actions

Likes
1
Downloads
42
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    ikp321-04 ikp321-04 Presentation Transcript

    • Manajemen dan Kualitas Perangkat Lunak IKP321 Unit Testing
    • Unit Perangkat Lunak Code Documentation Procedure Data Satuan terkecil Code Unit Method atau Function atau Procedure
    • 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
    • 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
    • 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)); }}
    • 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
    • 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
    • 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;
    • Implementasi Class if (a >= b) { max = a; } else { max = b; } if (c >= max) { max = c; } return max; }}
    • ●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)
    • JUnit dan Eclipse Eclipse IDE for Java Developers  http://www.eclipse.org/ downloads/ Unduh, Pasang, dan Jalankan Buat Java Project yang baru
    • 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 JUnit 4 test" Ubah nama folder ke folder "test"
    • 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 tjerdastangkas.blogspot.com/search/label/ikp321