SlideShare a Scribd company logo
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

More Related Content

What's hot

TestNG with selenium
TestNG with seleniumTestNG with selenium
TestNG with selenium
Gousalya Ramachandran
 
Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
Narendran Solai Sridharan
 
TestNG
TestNGTestNG
TestNG introduction
TestNG introductionTestNG introduction
TestNG introductionDenis Bazhin
 
Junit
JunitJunit
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
Levon Apreyan
 
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
Oleksiy Rezchykov
 
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
BugRaptors
 
Junit
JunitJunit
Junit
JunitJunit
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
Onkar Deshpande
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
Devvrat Shukla
 
JUnit Pioneer
JUnit PioneerJUnit Pioneer
JUnit Pioneer
Scott Leberknight
 
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
Narendra Pathai
 
Test ng
Test ngTest ng
Test ng
fbenault
 
Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
Srikrishna k
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
priya_trivedi
 
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
Ravikiran J
 

What's hot (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
 

Viewers also liked

Ifmasv Roundtable Sj City College09 May12
Ifmasv Roundtable   Sj City College09 May12Ifmasv Roundtable   Sj City College09 May12
Ifmasv Roundtable Sj City College09 May12
AndyFuhrman
 
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
 
Vagrant
VagrantVagrant
Capsule01 Creds2008
Capsule01 Creds2008Capsule01 Creds2008
Capsule01 Creds2008
capsule01
 
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
 
5 A 2008
5 A  20085 A  2008
5 A 2008
domienict
 
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 haine
Da Vinci
 
Crowdfunding 101
Crowdfunding 101Crowdfunding 101
Crowdfunding 101
Dave Gee
 
B2: The OpenSplice BlendBox
B2: The OpenSplice BlendBoxB2: The OpenSplice BlendBox
B2: The OpenSplice BlendBox
Angelo Corsaro
 
Ingalaterra Eta Portugal
Ingalaterra Eta PortugalIngalaterra Eta Portugal
Ingalaterra Eta Portugalguestd4e08
 

Viewers also liked (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
 

Similar to ikp321-04

8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
ssuserd0fdaa
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
Suman Sourav
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
OpenDaylight
 
Junit With Eclipse
Junit With EclipseJunit With Eclipse
Junit With Eclipse
Sunil kumar Mohanty
 
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
romanovfedor
 
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 cactus
Himanshu
 
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
Ahmed Ehab AbdulAziz
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
Ahmed M. Gomaa
 
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
 
L08 Unit Testing
L08 Unit TestingL08 Unit Testing
L08 Unit Testing
Ólafur Andri Ragnarsson
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
Amila Paranawithana
 
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
Vineet Reynolds
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
Pokpitch Patcharadamrongkul
 
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
Knoldus Inc.
 

Similar to 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
 

More from 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
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 

Recently uploaded (20)

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 

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