SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Nguyen Ngoc Anh
anhnn3@fpt.com.vn
Fu Hoa Lac, 3- 2013
Objectives

o Why testing?

o Basic principles

o How to choosing test case

o Test-First Programming

o Introduction to Junit

o Let’s do together!!!!


                     FUAgile: Unit Testing Basic   2
CRISIS




Numbers:
4.4 million cars recalled
Billions of $ loss.
Damage the brand

                            FUAgile: Unit Testing Basic   3
Desire vs. Reality

       Desired                                   Reality
Requirement
                        gap             Implementation
  Design



                    testing


                 FUAgile: Unit Testing Basic               4
Why testing?

o Ensuring QUALITY

o Managing RISKS

o Optimizing Return-On-Investment (ROI)

o Professionalism



                    FUAgile: Unit Testing Basic   5
Typical Production model

    Requirement


         Design


         Implement


                 Test

      FUAgile: Unit Testing Basic   6
Bug cost




FUAgile: Unit Testing Basic   7
Testing level

o Unit testing
   o On individual unit of source code (function, class, etc.)
   o Smallest testable part
   o Developer testing
o Integration testing
   o On groups of modules
o System testing
   o On complete integrated system



                       FUAgile: Unit Testing Basic               8
Basic Principles

o Be systematic

  o Haphazard testing & exhaustive testing are impossible.

  o test cases must be chosen carefully and systematically

o Do it early and often

  o Don’t leave testing until the end  debugging longer and
    more painful

  o test-first programming
                     FUAgile: Unit Testing Basic               9
Basic Principles

o Automate it

  o Nothing makes tests easier to run, and more likely to be
    run, than complete automation.

  o For regression test




                     FUAgile: Unit Testing Basic               10
Why Testing is Hard

o We want to

  o know when product is stable enough to launch

  o deliver product with known failure rate (preferably low)

  o offer warranty?




                      FUAgile: Unit Testing Basic              11
Why Testing is Hard

o But

  o it’s very hard to measure or ensure quality in software
  o residual defect rate after shipping:
    • 1 - 10 defects/kloc (typical)
    • 0.1 - 1 defects/kloc (high quality: Java libraries?)
    • 0.01 - 0.1 defects/kloc (very best: Praxis, NASA)
  o exhaustive testing is infeasible

  o statistical testing doesn’t work for software

                        FUAgile: Unit Testing Basic           12
Find bugs as cheaply and quickly as possible!




              FUAgile: Unit Testing Basic       13
Choosing Test Cases

o Key Idea #1: Partition the Input Space

  o input space is very large, but program is small  so
    behavior must be the “same” for whole sets of inputs

  o ideal test suite
     o identify sets of inputs with the same behavior

     o try one input from each set



                       FUAgile: Unit Testing Basic         14
Choosing Test Cases

Ex: multiply : BigInteger x BigInteger  BigInteger

partition BigInteger into:

   BigNeg, SmallNeg, -1, 0, 1, SmallPos, BigPos

pick a value from each class

   -265, -9 -1, 0, 1, 9, 265

test the 7 × 7 = 49 combinations

                     FUAgile: Unit Testing Basic      15
Choosing Test Cases

Ex2: max : int vs int  int

partition into:

    a < b, a = b, a > b

pick value from each class

    (1, 2), (1, 1), (2, 1)



                       FUAgile: Unit Testing Basic   16
Choosing Test Cases
0




       FUAgile: Unit Testing Basic   17
Choosing Test Cases

o Key idea #2: Boundary testing

  o include classes at boundaries of the input space

   zero, min/max values, empty set, empty string, null
  o why? because bugs often occur at boundaries
    o off-by-one errors

    o forget to handle empty container

    o overflow errors in arithmetic

                      FUAgile: Unit Testing Basic        18
Choosing Test Cases

EX: Find max value in a list of nonnegative integers. Assuming
that list is not empty.

public static int max(List<Integer> l) { ... }

    list length: length 0, length 1, length 2+

    max position: start, middle, end of list

    value of max: MIN_INT, negative, 0, positive, MAX_INT

                      FUAgile: Unit Testing Basic          19
Coverage
o all-statements: is every statement run by some test case?
 (common goal)

o all-branches: if every direction of an if or while statement (true
 or false) taken by some test case?

o all-paths: is every possible combination of branches – every
 path through the program – taken by some test case?



                        FUAgile: Unit Testing Basic               20
Test-first programming
2 approaches:

Code  Tests  Fix bugs (painful)

Write tests  Code           Test-first programming




        What is your choice?


                     FUAgile: Unit Testing Basic      21
Test-first programming
write tests before coding

specifically, for every method or class:
  1) write specification

  2) write test cases that cover the spec

  3) implement the method or class

  4) once the tests pass (and code coverage is sufficient), you’re done




                           FUAgile: Unit Testing Basic               22
JUnit

o Unit testing automation framework for Java

o Can do integration test

o Integrated in IDEs (Eclipse, NetBeans, IntelliJ, etc.)

o Must have tool for Java developers

                              http://www.junit.org/

                     FUAgile: Unit Testing Basic           23
JUnit
o A JUnit test case start with @Test

o Test case name start with testXXX()

o Using assertEquals, assertTrue, assertFalse…
@Test

public void testMaxAtStart(){

    ArrayList<Integer> list = new ArrayList<>();

    //add 5,2,3 to list

    assertEquals(MyClass.Max(list), 5);

}
                          FUAgile: Unit Testing Basic   24
JUnit
o If you expect an exception using

@Test(expected = SomeTypeOfException.class)
@Test(expected = IllegalArgumentException.class)

public void testMaxAtStart(){

    ArrayList<Integer> list = new ArrayList<>();

    MyClass.Max(list)

}



                        FUAgile: Unit Testing Basic   25
Let’s do together
Using Test-First programming

Ex1: Write a function with parameter is an integer n, if n<0 throw
IllegalArgumentException; otherwise
  • if n%3==0 return “Fizz”;

  • If n%5==0 return “Buzz”;

  • If n%3==0 and n%5==0 return “FizzBuzz”;

  • Else return the number itself

public static String fizzBuzz(int n) { ... }
                         FUAgile: Unit Testing Basic           26
Let’s do together
Using Test-First programming

Ex2: Find max value in a list of nonnegative integers. Assuming
that list is not empty.

public static int max(List<Integer> list) { ... }




                          FUAgile: Unit Testing Basic         27
Let’s do together
Using Test-First programming

Ex3: Find the union of 2 arrays of integers.

public static int[] union(int[] arr1, int[] arr2) { ... }




                          FUAgile: Unit Testing Basic       28

Weitere ähnliche Inhalte

Was ist angesagt?

05 junit
05 junit05 junit
05 junitmha4
 
Xp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocksguillaumecarre
 
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 practicesNarendra Pathai
 
Unit Testing with Python
Unit Testing with PythonUnit Testing with Python
Unit Testing with PythonMicroPyramid .
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeTed Vinke
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first stepsRenato Primavera
 
Introduction To J unit
Introduction To J unitIntroduction To J unit
Introduction To J unitOlga Extone
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
MUTANTS KILLER - PIT: state of the art of mutation testing system
MUTANTS KILLER - PIT: state of the art of mutation testing system MUTANTS KILLER - PIT: state of the art of mutation testing system
MUTANTS KILLER - PIT: state of the art of mutation testing system Tarin Gamberini
 

Was ist angesagt? (20)

05 junit
05 junit05 junit
05 junit
 
Mutation testing
Mutation testingMutation testing
Mutation testing
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Xp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocks
 
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
 
Junit
JunitJunit
Junit
 
Unit Testing with Python
Unit Testing with PythonUnit Testing with Python
Unit Testing with Python
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 
J Unit
J UnitJ Unit
J Unit
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
Introduction To J unit
Introduction To J unitIntroduction To J unit
Introduction To J unit
 
Java custom annotations example
Java custom annotations exampleJava custom annotations example
Java custom annotations example
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
3 j unit
3 j unit3 j unit
3 j unit
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
MUTANTS KILLER - PIT: state of the art of mutation testing system
MUTANTS KILLER - PIT: state of the art of mutation testing system MUTANTS KILLER - PIT: state of the art of mutation testing system
MUTANTS KILLER - PIT: state of the art of mutation testing system
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 

Andere mochten auch

Andere mochten auch (8)

Глеб Сахрай, PR-Technologies
Глеб Сахрай, PR-TechnologiesГлеб Сахрай, PR-Technologies
Глеб Сахрай, PR-Technologies
 
Business Essentials budget, strategy & human resources
Business Essentials budget, strategy & human resourcesBusiness Essentials budget, strategy & human resources
Business Essentials budget, strategy & human resources
 
Where Does Your Water Shed State Poster Contest
Where Does Your Water Shed State Poster ContestWhere Does Your Water Shed State Poster Contest
Where Does Your Water Shed State Poster Contest
 
Overview
OverviewOverview
Overview
 
Software testing and analysis
Software testing and analysisSoftware testing and analysis
Software testing and analysis
 
Bai giang trac dia dai cuong bk
Bai giang trac dia dai cuong bkBai giang trac dia dai cuong bk
Bai giang trac dia dai cuong bk
 
Virtual instrumentation (LabVIEW)
Virtual instrumentation (LabVIEW)Virtual instrumentation (LabVIEW)
Virtual instrumentation (LabVIEW)
 
VHT Education - OD1 - Google
VHT Education - OD1 - GoogleVHT Education - OD1 - Google
VHT Education - OD1 - Google
 

Ähnlich wie Fu agile#2 unit_testing

SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitAmr E. Mohamed
 
Test driven development
Test driven developmentTest driven development
Test driven developmentJohn Walsh
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)Amr E. Mohamed
 
5.Black Box Testing and Levels of Testing.ppt
5.Black Box Testing and Levels of Testing.ppt5.Black Box Testing and Levels of Testing.ppt
5.Black Box Testing and Levels of Testing.pptSyedAhmad732853
 
ch11lect1.ppt
ch11lect1.pptch11lect1.ppt
ch11lect1.pptImXaib
 
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytghch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytghssuser2d043c
 
Software testing
Software testingSoftware testing
Software testingBala Ganesh
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style GuideJacky Lai
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesDerek Smith
 
J unit presentation
J unit presentationJ unit presentation
J unit presentationPriya Sharma
 
Software testing definition
Software testing definitionSoftware testing definition
Software testing definitionHiro Mia
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Kiki Ahmadi
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 
Google test training
Google test trainingGoogle test training
Google test trainingThierry Gayet
 

Ähnlich wie Fu agile#2 unit_testing (20)

SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and Junit
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
5.Black Box Testing and Levels of Testing.ppt
5.Black Box Testing and Levels of Testing.ppt5.Black Box Testing and Levels of Testing.ppt
5.Black Box Testing and Levels of Testing.ppt
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Junit With Eclipse
Junit With EclipseJunit With Eclipse
Junit With Eclipse
 
Testing
TestingTesting
Testing
 
ch11lect1.ppt
ch11lect1.pptch11lect1.ppt
ch11lect1.ppt
 
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytghch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
 
ch11lect1.ppt
ch11lect1.pptch11lect1.ppt
ch11lect1.ppt
 
Software testing
Software testingSoftware testing
Software testing
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style Guide
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
Software testing definition
Software testing definitionSoftware testing definition
Software testing definition
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
Google test training
Google test trainingGoogle test training
Google test training
 

Kürzlich hochgeladen

Call Girl Number in Vashi Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Vashi Mumbai📲 9833363713 💞 Full Night EnjoyCall Girl Number in Vashi Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Vashi Mumbai📲 9833363713 💞 Full Night Enjoybabeytanya
 
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...astropune
 
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...Miss joya
 
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...Miss joya
 
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore EscortsCall Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escortsvidya singh
 
Vip Call Girls Anna Salai Chennai 👉 8250192130 ❣️💯 Top Class Girls Available
Vip Call Girls Anna Salai Chennai 👉 8250192130 ❣️💯 Top Class Girls AvailableVip Call Girls Anna Salai Chennai 👉 8250192130 ❣️💯 Top Class Girls Available
Vip Call Girls Anna Salai Chennai 👉 8250192130 ❣️💯 Top Class Girls AvailableNehru place Escorts
 
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Service
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort ServicePremium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Service
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Servicevidya singh
 
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...narwatsonia7
 
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune) Girls Service
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune)  Girls ServiceCALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune)  Girls Service
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune) Girls ServiceMiss joya
 
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...Garima Khatri
 
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...Miss joya
 
Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...narwatsonia7
 
Russian Call Girls in Pune Tanvi 9907093804 Short 1500 Night 6000 Best call g...
Russian Call Girls in Pune Tanvi 9907093804 Short 1500 Night 6000 Best call g...Russian Call Girls in Pune Tanvi 9907093804 Short 1500 Night 6000 Best call g...
Russian Call Girls in Pune Tanvi 9907093804 Short 1500 Night 6000 Best call g...Miss joya
 
Bangalore Call Girls Hebbal Kempapura Number 7001035870 Meetin With Bangalor...
Bangalore Call Girls Hebbal Kempapura Number 7001035870  Meetin With Bangalor...Bangalore Call Girls Hebbal Kempapura Number 7001035870  Meetin With Bangalor...
Bangalore Call Girls Hebbal Kempapura Number 7001035870 Meetin With Bangalor...narwatsonia7
 
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Deliverynehamumbai
 
High Profile Call Girls Coimbatore Saanvi☎️ 8250192130 Independent Escort Se...
High Profile Call Girls Coimbatore Saanvi☎️  8250192130 Independent Escort Se...High Profile Call Girls Coimbatore Saanvi☎️  8250192130 Independent Escort Se...
High Profile Call Girls Coimbatore Saanvi☎️ 8250192130 Independent Escort Se...narwatsonia7
 
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night EnjoyCall Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoybabeytanya
 
(Rocky) Jaipur Call Girl - 9521753030 Escorts Service 50% Off with Cash ON De...
(Rocky) Jaipur Call Girl - 9521753030 Escorts Service 50% Off with Cash ON De...(Rocky) Jaipur Call Girl - 9521753030 Escorts Service 50% Off with Cash ON De...
(Rocky) Jaipur Call Girl - 9521753030 Escorts Service 50% Off with Cash ON De...indiancallgirl4rent
 
Bangalore Call Girls Majestic 📞 9907093804 High Profile Service 100% Safe
Bangalore Call Girls Majestic 📞 9907093804 High Profile Service 100% SafeBangalore Call Girls Majestic 📞 9907093804 High Profile Service 100% Safe
Bangalore Call Girls Majestic 📞 9907093804 High Profile Service 100% Safenarwatsonia7
 

Kürzlich hochgeladen (20)

Call Girl Number in Vashi Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Vashi Mumbai📲 9833363713 💞 Full Night EnjoyCall Girl Number in Vashi Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Vashi Mumbai📲 9833363713 💞 Full Night Enjoy
 
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
 
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...
 
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...
 
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore EscortsCall Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
 
Vip Call Girls Anna Salai Chennai 👉 8250192130 ❣️💯 Top Class Girls Available
Vip Call Girls Anna Salai Chennai 👉 8250192130 ❣️💯 Top Class Girls AvailableVip Call Girls Anna Salai Chennai 👉 8250192130 ❣️💯 Top Class Girls Available
Vip Call Girls Anna Salai Chennai 👉 8250192130 ❣️💯 Top Class Girls Available
 
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Service
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort ServicePremium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Service
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Service
 
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...
 
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune) Girls Service
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune)  Girls ServiceCALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune)  Girls Service
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune) Girls Service
 
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...
 
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...
 
Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...
 
Russian Call Girls in Pune Tanvi 9907093804 Short 1500 Night 6000 Best call g...
Russian Call Girls in Pune Tanvi 9907093804 Short 1500 Night 6000 Best call g...Russian Call Girls in Pune Tanvi 9907093804 Short 1500 Night 6000 Best call g...
Russian Call Girls in Pune Tanvi 9907093804 Short 1500 Night 6000 Best call g...
 
Bangalore Call Girls Hebbal Kempapura Number 7001035870 Meetin With Bangalor...
Bangalore Call Girls Hebbal Kempapura Number 7001035870  Meetin With Bangalor...Bangalore Call Girls Hebbal Kempapura Number 7001035870  Meetin With Bangalor...
Bangalore Call Girls Hebbal Kempapura Number 7001035870 Meetin With Bangalor...
 
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
 
High Profile Call Girls Coimbatore Saanvi☎️ 8250192130 Independent Escort Se...
High Profile Call Girls Coimbatore Saanvi☎️  8250192130 Independent Escort Se...High Profile Call Girls Coimbatore Saanvi☎️  8250192130 Independent Escort Se...
High Profile Call Girls Coimbatore Saanvi☎️ 8250192130 Independent Escort Se...
 
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night EnjoyCall Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoy
 
sauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Service
sauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Servicesauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Service
sauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Service
 
(Rocky) Jaipur Call Girl - 9521753030 Escorts Service 50% Off with Cash ON De...
(Rocky) Jaipur Call Girl - 9521753030 Escorts Service 50% Off with Cash ON De...(Rocky) Jaipur Call Girl - 9521753030 Escorts Service 50% Off with Cash ON De...
(Rocky) Jaipur Call Girl - 9521753030 Escorts Service 50% Off with Cash ON De...
 
Bangalore Call Girls Majestic 📞 9907093804 High Profile Service 100% Safe
Bangalore Call Girls Majestic 📞 9907093804 High Profile Service 100% SafeBangalore Call Girls Majestic 📞 9907093804 High Profile Service 100% Safe
Bangalore Call Girls Majestic 📞 9907093804 High Profile Service 100% Safe
 

Fu agile#2 unit_testing

  • 2. Objectives o Why testing? o Basic principles o How to choosing test case o Test-First Programming o Introduction to Junit o Let’s do together!!!! FUAgile: Unit Testing Basic 2
  • 3. CRISIS Numbers: 4.4 million cars recalled Billions of $ loss. Damage the brand FUAgile: Unit Testing Basic 3
  • 4. Desire vs. Reality Desired Reality Requirement gap Implementation Design testing FUAgile: Unit Testing Basic 4
  • 5. Why testing? o Ensuring QUALITY o Managing RISKS o Optimizing Return-On-Investment (ROI) o Professionalism FUAgile: Unit Testing Basic 5
  • 6. Typical Production model Requirement Design Implement Test FUAgile: Unit Testing Basic 6
  • 7. Bug cost FUAgile: Unit Testing Basic 7
  • 8. Testing level o Unit testing o On individual unit of source code (function, class, etc.) o Smallest testable part o Developer testing o Integration testing o On groups of modules o System testing o On complete integrated system FUAgile: Unit Testing Basic 8
  • 9. Basic Principles o Be systematic o Haphazard testing & exhaustive testing are impossible. o test cases must be chosen carefully and systematically o Do it early and often o Don’t leave testing until the end  debugging longer and more painful o test-first programming FUAgile: Unit Testing Basic 9
  • 10. Basic Principles o Automate it o Nothing makes tests easier to run, and more likely to be run, than complete automation. o For regression test FUAgile: Unit Testing Basic 10
  • 11. Why Testing is Hard o We want to o know when product is stable enough to launch o deliver product with known failure rate (preferably low) o offer warranty? FUAgile: Unit Testing Basic 11
  • 12. Why Testing is Hard o But o it’s very hard to measure or ensure quality in software o residual defect rate after shipping: • 1 - 10 defects/kloc (typical) • 0.1 - 1 defects/kloc (high quality: Java libraries?) • 0.01 - 0.1 defects/kloc (very best: Praxis, NASA) o exhaustive testing is infeasible o statistical testing doesn’t work for software FUAgile: Unit Testing Basic 12
  • 13. Find bugs as cheaply and quickly as possible! FUAgile: Unit Testing Basic 13
  • 14. Choosing Test Cases o Key Idea #1: Partition the Input Space o input space is very large, but program is small  so behavior must be the “same” for whole sets of inputs o ideal test suite o identify sets of inputs with the same behavior o try one input from each set FUAgile: Unit Testing Basic 14
  • 15. Choosing Test Cases Ex: multiply : BigInteger x BigInteger  BigInteger partition BigInteger into: BigNeg, SmallNeg, -1, 0, 1, SmallPos, BigPos pick a value from each class -265, -9 -1, 0, 1, 9, 265 test the 7 × 7 = 49 combinations FUAgile: Unit Testing Basic 15
  • 16. Choosing Test Cases Ex2: max : int vs int  int partition into: a < b, a = b, a > b pick value from each class (1, 2), (1, 1), (2, 1) FUAgile: Unit Testing Basic 16
  • 17. Choosing Test Cases 0 FUAgile: Unit Testing Basic 17
  • 18. Choosing Test Cases o Key idea #2: Boundary testing o include classes at boundaries of the input space zero, min/max values, empty set, empty string, null o why? because bugs often occur at boundaries o off-by-one errors o forget to handle empty container o overflow errors in arithmetic FUAgile: Unit Testing Basic 18
  • 19. Choosing Test Cases EX: Find max value in a list of nonnegative integers. Assuming that list is not empty. public static int max(List<Integer> l) { ... } list length: length 0, length 1, length 2+ max position: start, middle, end of list value of max: MIN_INT, negative, 0, positive, MAX_INT FUAgile: Unit Testing Basic 19
  • 20. Coverage o all-statements: is every statement run by some test case? (common goal) o all-branches: if every direction of an if or while statement (true or false) taken by some test case? o all-paths: is every possible combination of branches – every path through the program – taken by some test case? FUAgile: Unit Testing Basic 20
  • 21. Test-first programming 2 approaches: Code  Tests  Fix bugs (painful) Write tests  Code Test-first programming What is your choice? FUAgile: Unit Testing Basic 21
  • 22. Test-first programming write tests before coding specifically, for every method or class: 1) write specification 2) write test cases that cover the spec 3) implement the method or class 4) once the tests pass (and code coverage is sufficient), you’re done FUAgile: Unit Testing Basic 22
  • 23. JUnit o Unit testing automation framework for Java o Can do integration test o Integrated in IDEs (Eclipse, NetBeans, IntelliJ, etc.) o Must have tool for Java developers http://www.junit.org/ FUAgile: Unit Testing Basic 23
  • 24. JUnit o A JUnit test case start with @Test o Test case name start with testXXX() o Using assertEquals, assertTrue, assertFalse… @Test public void testMaxAtStart(){ ArrayList<Integer> list = new ArrayList<>(); //add 5,2,3 to list assertEquals(MyClass.Max(list), 5); } FUAgile: Unit Testing Basic 24
  • 25. JUnit o If you expect an exception using @Test(expected = SomeTypeOfException.class) @Test(expected = IllegalArgumentException.class) public void testMaxAtStart(){ ArrayList<Integer> list = new ArrayList<>(); MyClass.Max(list) } FUAgile: Unit Testing Basic 25
  • 26. Let’s do together Using Test-First programming Ex1: Write a function with parameter is an integer n, if n<0 throw IllegalArgumentException; otherwise • if n%3==0 return “Fizz”; • If n%5==0 return “Buzz”; • If n%3==0 and n%5==0 return “FizzBuzz”; • Else return the number itself public static String fizzBuzz(int n) { ... } FUAgile: Unit Testing Basic 26
  • 27. Let’s do together Using Test-First programming Ex2: Find max value in a list of nonnegative integers. Assuming that list is not empty. public static int max(List<Integer> list) { ... } FUAgile: Unit Testing Basic 27
  • 28. Let’s do together Using Test-First programming Ex3: Find the union of 2 arrays of integers. public static int[] union(int[] arr1, int[] arr2) { ... } FUAgile: Unit Testing Basic 28

Hinweis der Redaktion

  1. I don’t want to frustrate you by bunch of testing terms. Just focus on thinking, process and how-tos.
  2. Global: 4.4 million cars recalled (http://wsws.org/articles/2010/feb2010/toyo-f12.shtml )In the first quarter of 2009, the company posted a $7.7 billion loss. The estimated loss for Toyota in the current financial year, calculated before the expansion of the recall process in January, is $5.5 billion.http://parttimembadegree.com/business-school-cases/toyota-recalls-pr-management-crisis/http://en.wikipedia.org/wiki/2009%E2%80%932011_Toyota_vehicle_recallsVN: “mua toy chonólành” – lost
  3. For ROI optimization, see the analysis of Rex Black on Managing the Testing Process: Practical Tools and Techniques for Managing Hardware and Software Testing
  4. In conclusion: Test a.s.a.pTesting is responsibilities of all including developers.