12
Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Embed Size (px)

Citation preview

Page 1: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Embedded Systems Software Training Center

Unit Testing Workshop

Copyright © 2012 DSR Corporation

Page 2: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Objectives

• Implement unit tests and complete unit-testing procedure on existing code from previous workshops.

Copyright © 2012 DSR Corporation

2

Page 3: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Agenda

1. Problem definition

2. Action items

3. Implementing unit-test technique

4. Code coverage analysis

Copyright © 2012 DSR Corporation

3

Page 4: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Embedded Systems Software Training Center

Problem definition

Copyright © 2012 DSR Corporations

Page 5: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Problem definition

Copyright © 2012 DSR Corporation

Foundations of Software Testing. ISTQB Certification. Dorothy Graham, Erik Van Veenendaal

5

Task:Perform unit-testing procedure on existing code of bluetooth file transfer application.

Deliviries: State diagram

State transition matrix

Source code (with implemented unit tests)

Unit tests results

Code coverage results

Page 6: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Embedded Systems Software Training Center

Action Items

Copyright © 2012 DSR Corporations

Page 7: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Action Items

Copyright © 2012 DSR Corporation

Foundations of Software Testing. ISTQB Certification. Dorothy Graham, Erik Van Veenendaal

• Prepare state diagram for BT connection, inquiry etc. Check all possible branches, return codes etc.

• Prepare state transition matrix for transfer protocol

• Design/Implement unit tests based on prepared diagram.

• Run unit tests.

• Check results.

• Got a code coverage.

• Tune tests if necessary, run 2nd pass, check results.

• The final step of this technique is to write test cases to exercise each of the four rules in the table.

• Test cases may be enhanced with EP and BVA approaches.

7

Page 8: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Embedded Systems Software Training Center

Unit tests implementation technique

Copyright © 2012 DSR Corporations

Page 9: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Unit tests implementation

Copyright © 2012 DSR Corporation

Foundations of Software Testing. ISTQB Certification. Dorothy Graham, Erik Van Veenendaal

9

#define unit_test_1 /* enter Pin */ /* could be move to header */

//#define unit_test_2

//#define unit_test_3

…..

#Ifndef unit_test_1

int get_pin_num() {…}

#else

int get_pin_num(){return (int)3;}

#endif

Page 10: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Embedded Systems Software Training Center

Code coverage analysis

Copyright © 2012 DSR Corporations

Page 11: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Code coverage example

Copyright © 2012 DSR Corporation

Foundations of Software Testing. ISTQB Certification. Dorothy Graham, Erik Van Veenendaal

11

void Drinker::Drink (bool beer, bool whiskey)

{if (beer)

{this->m_result = 1; /* Covered by Test ():1 */

} else

{this->m_result = -1; /* Covered by Test ():2 */

} if (whiskey)

{this->m_result = 2; /* Covered by Test ():1 */

} else

{this->m_result = -2; /* Covered by Test ():2 */

} }void Test() /* C0 (line coverage) is 100%, C1(branch coverage) is 100%, C2 (path coverage) is 50%.

{Drinker dude = new Drinker();dude.Drink(true, true);

Assert::AreEqual(m_result, 1);

dude.Drink(true, true);

Assert::AreEqual(m_result, 2);}

Page 12: Embedded Systems Software Training Center Unit Testing Workshop Copyright © 2012 DSR Corporation

Embedded Systems Software Training Center

Thank you

Copyright © 2012 DSR Corporations