Stubs and Drivers
Testing




 Powerpoint Templates
                        Page 1
What are STUBS and DRIVERS?


Stubs and Drivers are used in
integration testing for
    TOP-DOWN and BOTTOM-UP
testing respectively




              Powerpoint Templates
                                     Page 2
What is Top-Down Development?


Top-Down development: We first create the
“root” module and after that each module
(child) that is called by the “root”. Next we
move down the tree and consider each child
as a root for the next modules that need to be
developed. We repeat these steps until we
reach the “leaf” modules



                 Powerpoint Templates
                                         Page 3
What is Bottom-Up Development?


Bottom-Up development: Considering the
same tree of modules described in the
previous screen, we first develop the leaf
modules. Next, we move up one level and
develop the parent-modules (the ones that call
the leaf modules). After each level is complete,
we move up one level and develop it, until we
reach the “root” module.


                  Powerpoint Templates
                                         Page 4
Context –A Normal Program

                  Main             Main point of entry




            Powerpoint Templates
                                                 Page 5
Context –A Normal Program

                      Main             Main point of entry

                                                   Functions
Function 1   Function 2         Function 3         called in
                                                   main()




                Powerpoint Templates
                                                     Page 6
Context –A Normal Program

                      Main             Main point of entry

                                                   Functions
Function 1   Function 2         Function 3         called in
                                                   main()




                                                   Last layer
 function    function            function          of
                                                   functions


                Powerpoint Templates
                                                     Page 7
Context – No circular dependencies

                      Main             Main point of entry

                                                   Functions
Function 1   Function 2         Function 3         called in
                                                   main()




                                                   Last layer
 function    function            function          of
                                                   functions


                Powerpoint Templates
                                                     Page 8
Context – Modules, not Functions

                    Main             Main point of entry

                                                 Modules
 Module 1   Module 2           Module 3          called in
                                                 main()




                                                 Last layer
Module L    Module K          Module F           of
                                                 Modules


              Powerpoint Templates
                                                   Page 9
A Tipical Example



                       Module L




    Module K                                Module F
  (not developed)                          (not developed)



                    Powerpoint Templates
                                                       Page 10
A Tipical Example

 So how can we test MODULE L?
                       Module L




    Module K                                Module F
  (not developed)                          (not developed)



                    Powerpoint Templates
                                                       Page 11
A Tipical Example



                     Module L




 Module K Stub                           Module F Stub
  Dummy code that SIMULATES the functionality of the
               undeveloped modules


                  Powerpoint Templates
                                                  Page 12
Code Example - Stub
void functionWeTest(params..) {
       ………...
       int p = price(param1);
       ………..
}
void price(int param) { //this is the stub
      return 10; // We don’t care what the price is. We just
need a value so we can test the other function
}


                         Powerpoint Templates
                                                       Page 13
Let’s Move to Drivers


             (not developed)
               Module L




  Module K                          Module F




             Powerpoint Templates
                                          Page 14
Let’s Move to Drivers

  Dummy code that returns values from Module L and
                     Module K
                Module L Driver




  Module K                               Module F




                  Powerpoint Templates
                                               Page 15
A Tipical Example
void functionThatCallsPrice (params..) { //this is the driver
       int p = price(param1);
       printf(“Price is: %d”, p);
}
void price(int param) {
      //complex ecuations and DB interogations that
determin the real price
}



                          Powerpoint Templates
                                                         Page 16
Conclusions

No need to write all the modules in order to begin
testing
Stubs and Drivers are usually easy to create
The hard part is identifying what is essential and what
can be simulated
Stubs and Drivers can be thrown away once the
equivalent module is created



                    Powerpoint Templates
                                               Page 17

Stub Testing and Driver Testing

  • 1.
    Stubs and Drivers Testing Powerpoint Templates Page 1
  • 2.
    What are STUBSand DRIVERS? Stubs and Drivers are used in integration testing for TOP-DOWN and BOTTOM-UP testing respectively Powerpoint Templates Page 2
  • 3.
    What is Top-DownDevelopment? Top-Down development: We first create the “root” module and after that each module (child) that is called by the “root”. Next we move down the tree and consider each child as a root for the next modules that need to be developed. We repeat these steps until we reach the “leaf” modules Powerpoint Templates Page 3
  • 4.
    What is Bottom-UpDevelopment? Bottom-Up development: Considering the same tree of modules described in the previous screen, we first develop the leaf modules. Next, we move up one level and develop the parent-modules (the ones that call the leaf modules). After each level is complete, we move up one level and develop it, until we reach the “root” module. Powerpoint Templates Page 4
  • 5.
    Context –A NormalProgram Main Main point of entry Powerpoint Templates Page 5
  • 6.
    Context –A NormalProgram Main Main point of entry Functions Function 1 Function 2 Function 3 called in main() Powerpoint Templates Page 6
  • 7.
    Context –A NormalProgram Main Main point of entry Functions Function 1 Function 2 Function 3 called in main() Last layer function function function of functions Powerpoint Templates Page 7
  • 8.
    Context – Nocircular dependencies Main Main point of entry Functions Function 1 Function 2 Function 3 called in main() Last layer function function function of functions Powerpoint Templates Page 8
  • 9.
    Context – Modules,not Functions Main Main point of entry Modules Module 1 Module 2 Module 3 called in main() Last layer Module L Module K Module F of Modules Powerpoint Templates Page 9
  • 10.
    A Tipical Example Module L Module K Module F (not developed) (not developed) Powerpoint Templates Page 10
  • 11.
    A Tipical Example So how can we test MODULE L? Module L Module K Module F (not developed) (not developed) Powerpoint Templates Page 11
  • 12.
    A Tipical Example Module L Module K Stub Module F Stub Dummy code that SIMULATES the functionality of the undeveloped modules Powerpoint Templates Page 12
  • 13.
    Code Example -Stub void functionWeTest(params..) { ………... int p = price(param1); ……….. } void price(int param) { //this is the stub return 10; // We don’t care what the price is. We just need a value so we can test the other function } Powerpoint Templates Page 13
  • 14.
    Let’s Move toDrivers (not developed) Module L Module K Module F Powerpoint Templates Page 14
  • 15.
    Let’s Move toDrivers Dummy code that returns values from Module L and Module K Module L Driver Module K Module F Powerpoint Templates Page 15
  • 16.
    A Tipical Example voidfunctionThatCallsPrice (params..) { //this is the driver int p = price(param1); printf(“Price is: %d”, p); } void price(int param) { //complex ecuations and DB interogations that determin the real price } Powerpoint Templates Page 16
  • 17.
    Conclusions No need towrite all the modules in order to begin testing Stubs and Drivers are usually easy to create The hard part is identifying what is essential and what can be simulated Stubs and Drivers can be thrown away once the equivalent module is created Powerpoint Templates Page 17