Automated Testing for Embedded Software in C or C++


Published on

When software developers write automated tests for their software, the quality increases, the design improves and the project becomes more manageable. The development also becomes more fun!

In this presentation you will learn how to write automated tests for embedded software. You will see a live demonstration of writing an automated test for a feedback control algorithm in C. I will also talk about the benefits of writing tests and why it can actually improve your design and save you time.

When having a large set of automated tests it becomes valuable to run all tests automatically every time the code is changed. I will touch upon what is the best continuous integration setup for embedded software projects.

Sample code can be downloaded from

Published in: Technology
  • These are the Top 5 Best Java Training Institutes in Pune go to the link :l
    Are you sure you want to  Yes  No
    Your message goes here
  • keylabs is providing best devops online training..please go to the link below
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Automated Testing for Embedded Software in C or C++

  1. 1. Who is Lars Thorup?● Software developer ● Web: C# and JavaScript ● Embedded C++ for several devices using agile and automated testing● Coach: Teaching agile and automated testing● Advisor: Assesses software projects and companies● Founder and CEO of BestBrains and ZeaLake
  2. 2. Agenda● What is automated testing?● Unity, test framework for embedded C● Code example● Why should we write automated tests?● Questions
  3. 3. What is automated testing?● Developers write test ● Automated execution of all programs test programs
  4. 4. The Unity testing framework● Small memory footprint ● Many test functions ● ASSERT_TRUE● Pure C ● FAIL ● ASSERT_EQUAL● Optional tools to generate ● ASSERT_WITHIN test runners automatically ● ASSERT_BITS ● ASSERT_NOT_NULL● Alternatives in C++ ● ASSERT_MEMORY ● CppUnit ● Google Test
  5. 5. How do we handle dependencies?● The flow example ● a flow sensor ● generates pulse counts proportional to actual flow ● calculate average flow rate with regular intervals● The dependencies in the flow example ● the sensor creating the pulse interrupt ● recurring timer event ● thread safe counting● Decouple the dependencies ● Pulse: provide a callback to the FlowSensor component ● Timer and Counting: inject components into the Flow component● flow.c
  6. 6. Dependencies, on device main.c Listen GetRate flowSensor.c flow.c Pulse GetTime timerImpl.c Increment counterImpl.c
  7. 7. Dependencies, in test flowTest.c Pulse GetRate flow.c SetTime GetTime timerStub.c Increment counterImpl.c
  8. 8. Strategy for testing embedded software● Continuous Integration ● Automate build and test execution ● On desktop, simulator and/or the device● Break dependencies ● Hardware Abstraction Layer ● Simulate time measurements and timer events ● Standardize on frequently used stubs ● Use mock objects for testing protocols● Dependency injection ● Link time, where possible ● Run time, using function pointers, where necessary
  9. 9. Why should we write unit tests?● Speed up development ● Because of all the things we no longer have to waste time on ● Test Driven Development vs Debug Later Programming ● Avoid piling up technical dept (manual testing, bug fixing) ● Typing code is not where the bottleneck is● Find bugs faster ● Trivial bugs found immediately ● QA can do exploratory testing earlier and more extensively● Prevent bugs from reappearing ● Never fix a bug until we have a failing test● Improve the software design ● Loose coupling is required to write tests
  10. 10. Links to further resources● List of testing tools for C and C++ ●● Book ● embedded-c● Experiement on the benefits of TDD ●● Meetup groups ●
  11. 11. Questions