SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
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 Case

import 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

.E
Time: 0.043
There was 1 error:
1) testSimple(MaxThreeTest)java.lang.NoClassDefFoundError: MaxThree
    at MaxThreeTest.testSimple(MaxThreeTest.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
ssorImpl.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 more

FAILURES!!!
Tests run: 1,   Failures: 0,   Errors: 1
Implementasi Class

public 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

Contenu connexe

Tendances

TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
Denis Bazhin
 

Tendances (20)

TestNG with selenium
TestNG with seleniumTestNG with selenium
TestNG with selenium
 
TestNg_Overview_Config
TestNg_Overview_ConfigTestNg_Overview_Config
TestNg_Overview_Config
 
Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
 
TestNG
TestNGTestNG
TestNG
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
Junit
JunitJunit
Junit
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
 
Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit framework
 
Test ng for testers
Test ng for testersTest ng for testers
Test ng for testers
 
Junit
JunitJunit
Junit
 
Junit
JunitJunit
Junit
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
JUnit Pioneer
JUnit PioneerJUnit Pioneer
JUnit Pioneer
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practices
 
Test ng
Test ngTest ng
Test ng
 
Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 

En vedette

Odyssey Nov 2008
Odyssey Nov 2008Odyssey Nov 2008
Odyssey Nov 2008
jhibbs
 
Plan estratgicoparalaspersonasconte aysusfamilias
Plan estratgicoparalaspersonasconte aysusfamiliasPlan estratgicoparalaspersonasconte aysusfamilias
Plan estratgicoparalaspersonasconte aysusfamilias
Pepe Jara Cueva
 
Bolsafotos
BolsafotosBolsafotos
Bolsafotos
Skipje
 
Agency User Guide
Agency User GuideAgency User Guide
Agency User Guide
mayureshp
 
La coruña
La coruñaLa coruña
La coruña
C FM
 
Orange Language Travel Guide
Orange Language Travel GuideOrange Language Travel Guide
Orange Language Travel Guide
Orange BG
 
Acrp Presentation Jan 2009
Acrp Presentation Jan 2009Acrp Presentation Jan 2009
Acrp Presentation Jan 2009
thess1121
 
Osam Mardin Professional Samples1
Osam Mardin Professional Samples1Osam Mardin Professional Samples1
Osam Mardin Professional Samples1
mardinor
 
Ingalaterra Eta Portugal
Ingalaterra Eta PortugalIngalaterra Eta Portugal
Ingalaterra Eta Portugal
guestd4e08
 

En vedette (20)

Ifmasv Roundtable Sj City College09 May12
Ifmasv Roundtable   Sj City College09 May12Ifmasv Roundtable   Sj City College09 May12
Ifmasv Roundtable Sj City College09 May12
 
Odyssey Nov 2008
Odyssey Nov 2008Odyssey Nov 2008
Odyssey Nov 2008
 
Sph 106 Ch 10
Sph 106 Ch 10Sph 106 Ch 10
Sph 106 Ch 10
 
Plan estratgicoparalaspersonasconte aysusfamilias
Plan estratgicoparalaspersonasconte aysusfamiliasPlan estratgicoparalaspersonasconte aysusfamilias
Plan estratgicoparalaspersonasconte aysusfamilias
 
Bolsafotos
BolsafotosBolsafotos
Bolsafotos
 
Vagrant
VagrantVagrant
Vagrant
 
Capsule01 Creds2008
Capsule01 Creds2008Capsule01 Creds2008
Capsule01 Creds2008
 
Agency User Guide
Agency User GuideAgency User Guide
Agency User Guide
 
La coruña
La coruñaLa coruña
La coruña
 
Orange Language Travel Guide
Orange Language Travel GuideOrange Language Travel Guide
Orange Language Travel Guide
 
presentacion
presentacionpresentacion
presentacion
 
Acrp Presentation Jan 2009
Acrp Presentation Jan 2009Acrp Presentation Jan 2009
Acrp Presentation Jan 2009
 
Osam Mardin Professional Samples1
Osam Mardin Professional Samples1Osam Mardin Professional Samples1
Osam Mardin Professional Samples1
 
Beyond Europe: Priorities for Strengthening Agricultural Innovation Capacity ...
Beyond Europe: Priorities for Strengthening Agricultural Innovation Capacity ...Beyond Europe: Priorities for Strengthening Agricultural Innovation Capacity ...
Beyond Europe: Priorities for Strengthening Agricultural Innovation Capacity ...
 
5 A 2008
5 A  20085 A  2008
5 A 2008
 
Facebook for Business (Creating Fan Pages)
Facebook for Business (Creating Fan Pages)Facebook for Business (Creating Fan Pages)
Facebook for Business (Creating Fan Pages)
 
Black friday haine
Black friday haineBlack friday haine
Black friday haine
 
Crowdfunding 101
Crowdfunding 101Crowdfunding 101
Crowdfunding 101
 
B2: The OpenSplice BlendBox
B2: The OpenSplice BlendBoxB2: The OpenSplice BlendBox
B2: The OpenSplice BlendBox
 
Ingalaterra Eta Portugal
Ingalaterra Eta PortugalIngalaterra Eta Portugal
Ingalaterra Eta Portugal
 

Similaire à ikp321-04

Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
Priya Sharma
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
Greg.Helton
 

Similaire à ikp321-04 (20)

8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
 
Junit With Eclipse
Junit With EclipseJunit With Eclipse
Junit With Eclipse
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
3 j unit
3 j unit3 j unit
3 j unit
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discovering
 
Unit test
Unit testUnit test
Unit test
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
Junit and cactus
Junit and cactusJunit and cactus
Junit and cactus
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDD
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
UPC Testing talk 2
UPC Testing talk 2UPC Testing talk 2
UPC Testing talk 2
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
 
L08 Unit Testing
L08 Unit TestingL08 Unit Testing
L08 Unit Testing
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
 
A fresh look at Java Enterprise Application testing with Arquillian
A fresh look at Java Enterprise Application testing with ArquillianA fresh look at Java Enterprise Application testing with Arquillian
A fresh look at Java Enterprise Application testing with Arquillian
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Unit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxUnit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptx
 

Plus de Anung Ariwibowo (20)

isd314-06-association-mining
isd314-06-association-miningisd314-06-association-mining
isd314-06-association-mining
 
ikp213-unifikasi
ikp213-unifikasiikp213-unifikasi
ikp213-unifikasi
 
ikp213-06-horn-clause
ikp213-06-horn-clauseikp213-06-horn-clause
ikp213-06-horn-clause
 
ikp213-01-pendahuluan
ikp213-01-pendahuluanikp213-01-pendahuluan
ikp213-01-pendahuluan
 
ikd312-05-sqlite
ikd312-05-sqliteikd312-05-sqlite
ikd312-05-sqlite
 
ikd312-05-kalkulus-relasional
ikd312-05-kalkulus-relasionalikd312-05-kalkulus-relasional
ikd312-05-kalkulus-relasional
 
ikd312-04-aljabar-relasional
ikd312-04-aljabar-relasionalikd312-04-aljabar-relasional
ikd312-04-aljabar-relasional
 
ikd312-03-design
ikd312-03-designikd312-03-design
ikd312-03-design
 
ikd312-02-three-schema
ikd312-02-three-schemaikd312-02-three-schema
ikd312-02-three-schema
 
ikp213-02-pendahuluan
ikp213-02-pendahuluanikp213-02-pendahuluan
ikp213-02-pendahuluan
 
ikh311-08
ikh311-08ikh311-08
ikh311-08
 
ikh311-07
ikh311-07ikh311-07
ikh311-07
 
ikh311-06
ikh311-06ikh311-06
ikh311-06
 
ikh311-05
ikh311-05ikh311-05
ikh311-05
 
ikp321-svn
ikp321-svnikp321-svn
ikp321-svn
 
ikh311-04
ikh311-04ikh311-04
ikh311-04
 
ikp321-05
ikp321-05ikp321-05
ikp321-05
 
imsakiyah-jakarta-1433-09
imsakiyah-jakarta-1433-09imsakiyah-jakarta-1433-09
imsakiyah-jakarta-1433-09
 
ikh311-03
ikh311-03ikh311-03
ikh311-03
 
ikp321-03
ikp321-03ikp321-03
ikp321-03
 

Dernier

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 

ikp321-04

  • 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 Case import 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 .E Time: 0.043 There was 1 error: 1) testSimple(MaxThreeTest)java.lang.NoClassDefFoundError: MaxThree at MaxThreeTest.testSimple(MaxThreeTest.java:13) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl .java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce ssorImpl.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 more FAILURES!!! Tests run: 1, Failures: 0, Errors: 1
  • 8. Implementasi Class public 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
  • 13. JUnit dan Eclipse  Klik-kanan src, pilih New, pilih Class  Tuliskan nama class  MyClass
  • 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
  • 19. JUnit dan Eclipse  Klik-kanan pada Class Test Case,  Pilih Run As,  Pilih JUnit test
  • 21. Pustaka  http://www.vogella.de/articles/JUnit/article.html  starship.python.net/~tbryan/UnitTestTalk/index.html  tjerdastangkas.blogspot.com/search/label/ikp321