Design Article

How to use new unit testing tools & techniques to improve software quality

Mark Pitchford

4/6/2010 11:46 PM EDT

Unit Test has been around almost as long as software development itself. It just makes sense to take each application building block, build it in isolation, and execute it with test data to make sure that it does just what it should do without any confusing input from the remainder of the application.

In the past, the sting came from not being able to simply lift a software unit from its development environment, compile and run it " let alone supply it with test data.

For that to happen, you need a harness program acting as a holding mechanism that calls the unit, details any included files, "stubs" written to handle any procedure calls by the unit, and offers any initialization sequences which prepare data structures for the unit under test to act upon.

Not only was creating that process laborious, but it took a lot of skill. More often than not, the harness program required at least as much testing as the unit under test.

Perhaps more importantly, a fundamental requirement of software testing is to provide an objective, independent view of the software. The very intimate code knowledge required to manually construct a harness compromised the independence of the test process, undermining the legitimacy of the exercise.

The legacy from high integrity systems
In developing applications for the medical, railway, aerospace and defence industries, unit test is a mandatory part of a software development cycle - a necessary evil.

For these high integrity systems, unit test is compulsory, and the only question is how it might be completed in the most efficient manner possible. It is therefore no coincidence that many of the companies developing tools to provide such efficiency have grown from this niche market.

In non-safety-critical environments, perceived wisdom is that unit testing is a nice idea in principle, but commercially unjustifiable. A significant factor in that stance is the natural optimism which abounds at the beginning of any project. At that stage, why would anyone spend money on careful unit testing? There are great engineers in the team, the design is solid, sound management is in place. What could possibly go wrong?

However, things can, and do go wrong, and while unit test can't guarantee success, it certainly helps minimise failure. So, if we look at the tools designed and proven to provide quick and easy unit tests in high integrity systems, it makes sense that the same unit tests would provide a solid solution for those working on commercially developed software as well.

When is unit test justifiable?
Unit testing cannot always be justified. And, sometimes it remains possible to perform unit test from first principles, without the aid of any test tool at all.

There are pragmatic judgements to be made.

Sometimes that judgment is easy. If the software fails, what are the implications? Will anyone be killed, as might be the case in aircraft flight control? Will the commercial implications be disproportionately high, as exemplified by a continuous plastics production plant? Or are the costs of recall extremely high, perhaps in a car's engine controller? In these cases, extensive unit testing is essential and any tools that aid in that purpose make sense.

On the other hand, if software is developed purely for internal use or is perhaps a prototype, then the overhead in unit testing all but the most vital of procedures would be prohibitive.

As you might expect, there is a grey area. Suppose the application software controls a mechanical measuring machine where the quantity of the devices sold is low and the area served is localized. The question becomes: Would the occasional failure be more acceptable than the overhead of unit test?

In these circumstances, it's useful to prioritize the parts of the software which are either critical or complex. If a software error leads to a strangely coloured display or a need for an occasional reboot, it may be inconvenient but not in itself justification for unit test. On the other hand, the unit test of code which generates reports showing whether machined components are within tolerance may be vital.


Next:




The Heretic

4/8/2010 2:13 PM EDT

You spent 5 pages telling me what I already know, how about some solid information on these tools you're sing the praises of.

Sign in to Reply



ico

4/9/2010 1:35 AM EDT

The same for the recent interview of Jack to a Agile advocate.

They advocate the methodology a lot, but have no any practical unit testing or agile framework to real world embedded system design, just some framework for desktop host OS that we have known even better than them.

As unit testing/TDD will increase cost, is there really an easy to use and not too costly solution to unit testing/TDD on embedded system?

I adopt TDD and unit testing on my desktop application now, but I still found no cheap and good way to do TDD on embedded system.

Sign in to Reply



jasper77

4/26/2010 11:51 AM EDT

I would have liked this article to touch on the challenges embedded systems pose on unit testing. For example, it's nice if your code can compile with a host compiler so you can run your unit tests there, but if not, you would have to run them on your target, which may not have enough space for all the tests at once. This article also skips over any design-for-testability issues; when you're used to structured design it can be hard to see how unit testing is possible in the first place, and a whole lot of embedded software is written with structured design.

The agile advocate Jack interviewed actually has a lot of embedded experience. I saw his talk on TDD in C at a seminar specific to embedded systems, and it was clear he knows this stuff. He's writing a book on TDD in C and I'm looking forward to it coming out later this year.

Sign in to Reply



Please sign in to post comment

Navigate to related information

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)

Feedback Form