Developing tests through stories - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Developing tests through stories

Description:

Developing tests through stories Part of the hints for Assignment 1 Assignment 1 You are provided with the following functions in C++ and Assembly Language ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 14
Provided by: uca148
Category:

less

Transcript and Presenter's Notes

Title: Developing tests through stories


1
Developing tests through stories
  • Part of the hints for Assignment 1

2
Assignment 1
  • You are provided with the following functions
    in C and Assembly Language versions
  • void WriteLEDValues(int whichLEDvalues)
  • Writes value to the Blackfin LED port register
  • unsigned int ReadCurrentLEDValues(void)
  • Reads current value in Blackfin LED port register
  • void InitFlashCPP_DrSmithVersion(void)
  • Configures EBIU to allow Flash port to be
    activated
  • void InitFlashPortCPP_DrSmithVersion(void)
  • Configures the Flash port to allow read / write
    of LED register

3
You must develop and test
  • void My_InitLEDInterface(void)
  • Initializes the LED interface, turning all the
    LEDs off
  • void TurnOnLED(int whichLED)
  • Turns on LED whichLED WITHOUT changing the values
    of the other LEDs
  • void TurnOffLED(int whichLED)
  • Turns off LED whichLED WITHOUT changing the
    values of the other LEDs
  • void TogglefLED(int whichLED)
  • Toggles LED whichLED WITHOUT changing the values
    of the other LEDs. To-toggle- if on, turn off
    if off turn on

4
Test 1 Imagine all routines work
  • The story to be tested
  • If the My_InitLEDInterface( ) routine, then all
    the LEDs must be off
  • So the necessary test code to add into a test
    project isin the Assignment1_Test directory is
  • Test(All_LEDSoff_onInitialization)
  • unsigned int currentLEDValues 0xFF
  • unsigned int expectedLEDValues 0x00 //
    All off
  • My_InitLEDInterface( ) currentLEDValues
    ReadCurrentLEDValues( )CHECK(expectedLEDValue
    s, currentLEDValues)

5
In Assignment1 directory
  • Add the file My_InitLEDInterfaceCPP.cpp
  • Add this code into the file, and complete
  • void My_InitLEDInterface(void)
  • // Use the provided functions to initialize
    the EBIU
  • // Use the provided functions to initialize
    the LED port
  • Link the My_InitLEDInterfaceCPP.cpp into the
    tests in the Assignment 1 project
  • Check that the test passes

6
Test 2 Can I turn on LED 1?
  • Imagine that TurnOnLED(int whichLED) works
  • Image just 3 LED present
  • LED 1 ON requires LED register to have bit
    pattern 0x01
  • LED 2 ON requires LED register to have bit
    pattern 0x02
  • LED 3 ON requires LED register to have bit
    pattern 0x04
  • LED 1 ON and LED 2 ON requires LED register to
    have bit pattern 0x01 and 0x02 0x03

7
Is LED 3 on?
  • define LED3BITPATTERNMASK 0x4
  • // Read Current LED register currentLEDBitPatter
    n ReadCurrentLEDValues( )
  • currentLED3BitPattern currentLEDBitPattern
    LED3BITPATTERNMASK
  • if (currentLED3BitPattern 0) LED 3 off
  • if ((currentLED3BitPattern ! 0) LED 3 on //
    Poor check
  • // Better written test
  • if ((currentLED3BitPattern
    LED3BITPATTERNMASK ) LED 3 on

8
Test 2 Can I turn on LED 1?
  • Imagine that TurnOnLED(int whichLED) works
  • define LED1BITPATTERNMASK 0x1
  • define LED2BITPATTERNMASK 0x2
  • define LED3 BITPATTERNMASK 0x4
  • Test(TurnOn_LED1)
  • unsigned int currentLED1Values 0xFF
  • unsigned int expectedLED1Value 0x01 //
    LED 1 on
  • My_InitLEDInterface( )
  • TurnOnLED(1)currentLEDValues
    ReadCurrentLEDValues( )
  • currentLED1Value currentLEDValues
    LED1BITPATTERNMASK CHECK(expectedLEDValue,
    currentLED1Value)
  • 1

9
Test 3 You can put the tests in a loop
  • Test(TurnOn_AllLights)
  • unsigned int currentLEDValues 0xFF
  • unsigned int expectedLEDbitPattern 0x01
  • unsigned int chooseLEDbitPattern 0x01
  • My_InitLEDInterface( )
  • for (int count 1 count lt 7 count)
  • TurnOnLED(count)currentLEDValues
    ReadCurrentLEDValues( )
  • countLEDValue currentLEDValues
    chooseLEDbitPattern CHECK(expectedLEDbitPattern,
    countLEDValue )
  • expectedLEDbitPattern expectedLEDbitPatter
    n ltlt 1 Adjust result
  • chooseLEDbitPattern chooseLEDbitPattern
    ltlt 1

10
But those were bad tests
  • The requirement was for TurnOnLED( ) was to turn
    on one LED WITHOUT changing the other LEDs
  • We never tested that

11
Test 2 Can I turn on LED 1 without chaging LED2?
  • define LED1BITPATTERNMASK 0x1
  • define LED2BITPATTERNMASK 0x2
  • Test(TurnOn_LED1_Better)
  • unsigned int currentLED1Values 0xFF
  • My_InitLEDInterface( )
  • TurnOnLED(2)
  • unsigned int expectedLED2Value
    LED2BITPATTERNMASK // 2 on
  • TurnOnLED(1)
  • unsigned int expectedLED1Value
    LED1BITPATTERNMASK // 1 on currentLEDValues
    ReadCurrentLEDValues( )
  • currentLED1Value currentLEDValues
    LED1BITPATTERNMASK
  • currentLED2Value currentLEDValues
    LED2BITPATTERNMASK CHECK(expectedLED1Value,
    currentLED1Value) // 1 was onCHECK(expectedLED
    2Value, currentLED2Value) // LED 2 stayed on
  • 1

12
So I will now let you finish off developing and
testing the code for
  • void TurnOnLED(int whichLED)
  • Turns on LED whichLED WITHOUT changing the values
    of the other LEDs
  • void TurnOffLED(int whichLED)
  • Turns off LED whichLED WITHOUT changing the
    values of the other LEDs
  • void TogglefLED(int whichLED)
  • Toggles LED whichLED WITHOUT changing the values
    of the other LEDs. To-toggle- if on, turn off
    if off turn on

13
How many tests are needed?
  • Enough
  • Too many and you never finish the assignment
  • Too few and the assignment may fail
  • Make representative tests of the critical ideas
  • E.g turn on 1 and 2 check 1 stays on and 3 and
    4 stay off
  • E.g turn on 2 and 5 check 2 stays on and 1, 3
    and 4 stay off
Write a Comment
User Comments (0)
About PowerShow.com