SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Destaque

Ifmasv Roundtable Sj City College09 May12
Ifmasv Roundtable   Sj City College09 May12Ifmasv Roundtable   Sj City College09 May12
Ifmasv Roundtable Sj City College09 May12AndyFuhrman
 
Odyssey Nov 2008
Odyssey Nov 2008Odyssey Nov 2008
Odyssey Nov 2008jhibbs
 
Plan estratgicoparalaspersonasconte aysusfamilias
Plan estratgicoparalaspersonasconte aysusfamiliasPlan estratgicoparalaspersonasconte aysusfamilias
Plan estratgicoparalaspersonasconte aysusfamiliasPepe Jara Cueva
 
Bolsafotos
BolsafotosBolsafotos
BolsafotosSkipje
 
Capsule01 Creds2008
Capsule01 Creds2008Capsule01 Creds2008
Capsule01 Creds2008capsule01
 
Agency User Guide
Agency User GuideAgency User Guide
Agency User Guidemayureshp
 
La coruña
La coruñaLa coruña
La coruñaC FM
 
Orange Language Travel Guide
Orange Language Travel GuideOrange Language Travel Guide
Orange Language Travel GuideOrange BG
 
Acrp Presentation Jan 2009
Acrp Presentation Jan 2009Acrp Presentation Jan 2009
Acrp Presentation Jan 2009thess1121
 
Osam Mardin Professional Samples1
Osam Mardin Professional Samples1Osam Mardin Professional Samples1
Osam Mardin Professional Samples1mardinor
 
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 ...LINKInnovationStudies
 
Facebook for Business (Creating Fan Pages)
Facebook for Business (Creating Fan Pages)Facebook for Business (Creating Fan Pages)
Facebook for Business (Creating Fan Pages)CreAgent Marketing
 
Black friday haine
Black friday haineBlack friday haine
Black friday haineDa Vinci
 
Crowdfunding 101
Crowdfunding 101Crowdfunding 101
Crowdfunding 101Dave Gee
 
B2: The OpenSplice BlendBox
B2: The OpenSplice BlendBoxB2: The OpenSplice BlendBox
B2: The OpenSplice BlendBoxAngelo Corsaro
 
Ingalaterra Eta Portugal
Ingalaterra Eta PortugalIngalaterra Eta Portugal
Ingalaterra Eta Portugalguestd4e08
 

Destaque (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
 

Semelhante a ikp321-04

Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightOpenDaylight
 
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 discoveringromanovfedor
 
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_v2Tricode (part of Dept)
 
Junit and cactus
Junit and cactusJunit and cactus
Junit and cactusHimanshu
 
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 TDDAhmed Ehab AbdulAziz
 
J unit presentation
J unit presentationJ unit presentation
J unit presentationPriya Sharma
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnitGreg.Helton
 
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 ArquillianVineet Reynolds
 
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.pptxKnoldus Inc.
 

Semelhante a 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
 

Mais 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
 

Último

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Último (20)

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.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