Software quality is one of those issues that gets most attention when it's noticeably lacking. What is meant by the term "software quality", and how can we ensure that it is present?
A well known definition of software quality is "software that is delivered on time, within budget and to specification". However, in today's fast moving software development environment, where the specification is out of date before the team has been put together, this will no longer fly as a working definition of software quality.
Early identification and rectification of errors saves time and money. In today's business environment, systems are competitive tools and not just cost savers. Systems that don't perform leave you or your client either unable to operate, or at a disadvantage. In the tight time-scales of today's opportunities, it is then too late to seek the problem. Quality is either built in or it is not.
The forces of change
The only constant in IT is change. Predicting the direction of change is an industry in itself.
Gone is the old style of development, where user requirements are documented in a detailed specification, and then handed to the designers, who create a design coded by an army of programmers, and then tested by an army of testers. Today's processes are short and sharp; naturally adaptive and encouraging of change. Today's computers are business tools - actively participating to create competitive advantage. Today's software development processes are adapting accordingly.
How do we manage software development in an ever-changing environment, in a way that encourages change? The answer is an iterative development process, which delivers business advantage in small, fast increments.
How do we control quality in this environment? Clearly, just doing user testing at the end is not enough: By the time users have found and reported bugs, the team is well into the next increment. The cost of tracking, tracing and fixing such bugs is excessive. To draw a parallel with the construction industry, it's easier to make changes while the mortar is still wet, than to chip away after it's set. Software developers are no different: they must find the bugs as early in the process as possible - while the mortar is still wet.
Quality FIRST
Quality cannot be an after-the-fact issue: we can test after the fact, but true quality is built in: planned for, designed, and an integral part of the development process. It ought to be a natural part of what developers do all the time. Two major factors indicate this:
Development cycles are too short to allow for long testing periods at the end of each increment.
The cost of change during development is a small fraction of the cost of change once the bugs have been deployed.
A factor that mitigates against deeper quality sentiment, however, is the perceived lack of tangible benefit: "I wrote 1 000 lines of code today", versus, "I wrote 300 lines of tested code today". In many environments, more is better and 1 000 wins hands-down against 300 (no matter how many times that code has to be redone).
So, what tools are there that will help to bring a quality focus into software, earlier in the process? Sadly, there are few. You need to depend on in-house built test harnesses and test code developed by the programmers themselves. You also need a leadership team that cracks the quality whip with monotonous regularity - frequently the same leadership team has to balance the cost/time/scope equation. Quality suffers.
A major drawback of writing test code is the fact that the test code itself can have bugs. This leads to debugging the tests! Who quality controls the test code?
Most software testing and quality tools focus on verifying that the software works at a functional level. Few tools focus on testing before and during coding. Contrast this with the fact that, long before software becomes "functional", it exists first as a design; then as logically grouped "units" of software. These units are only later tied together so that they collaborate to produce the chunks of functionality that users see.
If software quality is to be built in, testing must focus first on guaranteeing the quality of these "units". The units themselves perform micro-tasks in fulfilment of the design; an arrangement viewed as contractual. In verifying unit quality, testing will verify performance against a "contract". Only later in the process will it also need to verify the chunks of functionality.
What is needed is a tool that will underpin quality through the development process that enables you to start testing the software, almost before it exists.
eXtreme testing
A radical new approach to software development that has been gaining popularity is eXtreme programming (often referred to as XP). XP was first showcased on the Chrysler C3 Payroll project and was the brainchild of Kent Beck, Ron Jeffries and others. An interesting aspect of XP is the notion of eXtreme testing.
This embraces the idea that before you write a line of code, you should have defined and written your unit tests. But how can you write the tests before you write the code?
In Smalltalk this is simplicity, and XP was first successfully applied in a Smalltalk environment. In most other languages, Java and C++ included, this is more challenging - you cannot write code that depends on other code that does not yet exist. The answer lies in a means to define your tests independently of your code, whether or not that code has been written.
Tests, then code
To encourage managers and developers to include aggressive unit testing as part of the lifecycle, it needs to add value beyond just finding bugs. "Just finding bugs" should be enough reason in itself, but the perception and reality seem poles apart. What value can defining tests early yield then?
For a start, defining the tests first forces developers to understand exactly what they will be coding - and to think about how their code will be used by other code in the system, rather than on how they are going to write the code. This emphasises the external interface of the unit of code, rather than its internal workings. An emphasis on this "contract" focuses developers on developing what is needed to satisfy requirements, which results in less code and fewer bugs.
Progress indicators
Ever ask a programmer how far they are and get the answer 80%, then discover that the last 20% takes 80% of the time? Having tests in place allows developers and management alike to track progress at a very fine-grained level. There are two measures here: The first is the number of tests that pass gives an indication of actual progress for specific units. The second is the total number of tests defined provides a metric of how much of the system is in place. Add this to the number and percentage of tests that pass and you have some powerful progress indicators.
Safe changes
How many times have you seen a "small change" that "just takes a minute" bring a system to its knees? Having a suite of unit tests in place allows errors in these small changes to be caught immediately they are introduced. A simple rule that states that no unit is released unless all the tests pass works wonders. You must have the tests in the first place and be able to monitor their relevance and accuracy.
The growing refactoring movement, another discipline practised by the proponents of XP, sees code cleaned up before functional changes are made. For refactoring to work, you must have tests that ensure that none of your "clean-up" changes break anything in the existing. Here the tests protect your code and the investment.
This suggests that testing early will save more time and money than testing later. It also contributes to getting the required functionality delivered without the expectation of comeback once the team has moved to the next increment.
XML, Java and testing
XML is a meta-language - a language used to define languages. Using XML we can specify sets of rules and definitions. A set of rules and definitions in XML is known as a DTD. A DTD can be used to define the format and rules for test data. Freely available tools for editing XML content make it possible to define test data using a DTD. A test framework to load and execute tests can use this data to execute tests. XML also becomes the natural medium for writing out test logs since it is inherently structured and can easily be imported into applications ranging from relational databases to spreadsheets and word processors.
This combination of Java and XML makes it feasible to define tests independently of the code under test and run them whenever and as often as you like. Even non-programmers and juniors can help define some of the tests, and anybody can run them.
Want to know more?
Turning this ideal into a reality is the topic of a half-day tutorial to be presented at OOPSLA 99 in Denver, Colorado. The tutorial walks through theory and principles. It then demonstrates how XML combined with Java language features can be applied to build a framework enabling the kind of testing discussed here. The demonstrations include a working test framework built on these principles.
Nigel Bakker of Software Futures and Chris Nel of FutureWorks are presenting "Automating software testing in Java using beans and reflection."
For more information see http://www.acm.org/sigplan/oopsla, the OOPSLA 99 home page.

