Upload
lars-thorup
View
4.490
Download
3
Embed Size (px)
DESCRIPTION
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 http://www.zealake.com/public/embedded-autotest.zip
Citation preview
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
Agenda● What is automated testing?
● Unity, test framework for embedded C
● Code example
● Why should we write automated tests?
● Questions
What is automated testing?● Developers write test
programs● Automated execution of all
test programs
The Unity testing framework● Small memory footprint
● Pure C
● Optional tools to generate test runners automatically
● Alternatives in C++● CppUnit● Google Test
● Many test functions● ASSERT_TRUE● FAIL● ASSERT_EQUAL● ASSERT_WITHIN● ASSERT_BITS● ASSERT_NOT_NULL● ASSERT_MEMORY
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
Dependencies, on device
main.c
flow.c
counterImpl.c
timerImpl.c
flowSensor.c
Listen
Pulse
Increment
GetRate
GetTime
Dependencies, in test
flowTest.c
flow.c
counterImpl.c
timerStub.c
Pulse
Increment
GetRate
SetTime
GetTime
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
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
Links to further resources● List of testing tools for C and C++
● http://www.opensourcetesting.org/unit_c.php
● Book● http://pragprog.com/titles/jgade/test-driven-development-for-
embedded-c
● Experiement on the benefits of TDD● http://www.infoq.com/news/2009/03/TDD-Improves-Quality
● Meetup groups● http://www.meetup.com/Test-Driven-Developers-Bay-Area/
Questions