Feeds

Driven to test-action

A practical view of unit testing

Internet Security Threat Report 2014

Comment Test-Driven Development (TDD) has increased in popularity both as a practice and as a term. Although there is a strong association with Extreme Programming, more generally there is a certain set of practices that can be honed in on and applied across various development models.

headshot_Kevlin_Henney (large teaser)

Decoupling TDD from XP, which specifically focuses on the terms 'programmer tests' and 'test-first programming', and understanding it as a set of microprocess practices in its own right, makes it a more general and useful tool for programmers, regardless of the development macroprocess they are in.

Unit testing and more

The term TDD is often mistakenly used as a synonym for "unit testing". The relationship between the two is that unit testing forms part of TDD, but there is more to TDD than just unit testing. Both critics and advocates often miss that metonymic distinction.

Unit testing is a general notion that can be employed and practised in many ways, whether up-front documentation of test plans associated with up-front documentation of detailed designs in the classic waterfall approach (think Niagara Falls and people in barrels), or more informally by individual programmers seeking confidence in their own work and applying the simple tool of an assertion in a test case that exercises some code they have written.

TDD places unit testing in the context of agile development by motivating it in a different way from traditional testing approaches, which typically borrow from the classic V model of testing - a smokily mirrored view of the waterfall development lifecycle that emphasises testing but divorces it from other activities making up the main flow of development [1].

Effective unit testing can be seen to rest on the foundation of programmer testing responsibility, automated tests and example-based tests. TDD drives that through the design-focused activities of active test writing, sufficient design and refactoring.

Programmer testing responsibility

Unit tests are sometimes called programmer tests to differentiate them from system-level tests carried out in a separate testing role or department. It is important to remember that testing a unit is not the same as testing a system. Testing a system involves the software combination of the many code units, whatever their granularity, and the elements of the system external to the code, e.g. target software environment, configuration and broad usage. Units test as a whole, rather than as integrated parts, and are isolated from the external environment.

Of course, there is a natural tension in any development process between the responsibilities each role can include and the control it can exercise. A development role needs to be broad enough to connect to the range of activities involved in software development, but cohesive enough and appropriately sized that responsibilities are not overwhelming. For the role of developer, the organisational pattern Developer Controls Process defines such a focus, and includes the following brief [2]:

"Responsibilities of developers include understanding requirements, reviewing the solution structure algorithm with peers, building the implementation, and performing unit testing."

However, this does not limit or define the whole range of testing activities. The system-level perspective is explicitly covered in patterns such as Engage Quality Assurance and Application Design Is Bounded by Test Design. The inclusion of a code-testing responsibility in the programmer's canon also receives strong support from more orthodox testing perspectives [3]:

"I find the projects I work on usually go more smoothly when programmers do some unit and component testing of their own code. Through the ascendance of approaches like Extreme Programming, such a position is becoming less controversial. [...] So, a good practice is to adopt a development process that provides for unit testing, where programmers find bugs in their own software, and for component testing, where programmers test each other's software (this is sometimes called 'code swapping'). Variations on this approach use concepts like pair programming and peer reviews of automated component test stubs or harnesses."

However, sometimes responsibility can also translate to burden. Just stating that unit testing is a programmer's responsibility does not offer guidance as to how the responsibility can be met in practical terms, which is where the other practices listed earlier fit in.

Choosing a cloud hosting partner with confidence

Next page: Automated tests

More from The Register

next story
Netscape Navigator - the browser that started it all - turns 20
It was 20 years ago today, Marc Andreeesen taught the band to play
Sway: Microsoft's new Office app doesn't have an Undo function
Content aggregation, meet the workplace ... oh
Sign off my IT project or I’ll PHONE your MUM
Honestly, it’s a piece of piss
Return of the Jedi – Apache reclaims web server crown
.london, .hamburg and .公司 - that's .com in Chinese - storm the web server charts
NetWare sales revive in China thanks to that man Snowden
If it ain't Microsoft, it's in fashion behind the Great Firewall
Chrome 38's new HTML tag support makes fatties FIT and SKINNIER
First browser to protect networks' bandwith using official spec
prev story

Whitepapers

Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
Win a year’s supply of chocolate
There is no techie angle to this competition so we're not going to pretend there is, but everyone loves chocolate so who cares.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Intelligent flash storage arrays
Tegile Intelligent Storage Arrays with IntelliFlash helps IT boost storage utilization and effciency while delivering unmatched storage savings and performance.