background preloader

Quality

Facebook Twitter

Metric definitions. Writing good unit tests, Part 1: Follow your GUTs. Just like production code, test code needs to be rigorously examined to ensure it's clean and bug free. In this first half of a two-part article, Klaus Berg makes the case for why good unit tests are as important as high-quality production code, then provides a comprehensive listing of agile tools and best practices used to improve the internal quality of test code.

Level: Intermediate Code quality is an important topic, but the definition of quality varies. According to the ISO 9126 standard, you can distinguish between internal quality, external quality, and quality in use. In the past, most companies looked only at production code quality, but that shouldn't be the end of your quest for better code. In this two-part article you'll get an overview of software quality -- how we define it and improve it -- followed by an introduction to methods, tools, and best practices for writing good unit test code. Software quality: How to define it, how to improve it. Writing good unit tests, Part 2: Follow your nose. Klaus Berg continues his in-depth investigation of tools and best practices for programming with GUTs. Get tips for writing cleaner and more efficient assertions with the help of a matching library (Hamcrest) and handling checked and unchecked exceptions in JUnit 3 and 4 and TestNG.

The remainder of the article focuses on refactoring test code, first explaining why it's important and then revealing the three layers of code smell that indicate something's rotten. This article is packed with tips and trivia for the code quality addict. Level: Intermediate The first half of this article presented best practices for writing test code, both from a technical angle and from a process-oriented one. Code coverage tools can help you measure how well your tests perform with respect to executing the different statements and branches of your system under test.

The second half of the article will focus on refactoring test code, from answering the question "Why refactor test code? " Listing 1. Open Source Systems Monitoring and Management Software | Hyperic. Mocks Aren't Stubs. The term 'Mock Objects' has become a popular one to describe special case objects that mimic real objects for testing. Most language environments now have frameworks that make it easy to create mock objects.

What's often not realized, however, is that mock objects are but one form of special case test object, one that enables a different style of testing. In this article I'll explain how mock objects work, how they encourage testing based on behavior verification, and how the community around them uses them to develop a different style of testing. I first came across the term "mock object" a few years ago in the XP community. But as often as not I see mock objects described poorly. This difference is actually two separate differences. (In the earlier version of this essay I had realized there was a difference, but combined the two differences together. Regular Tests I'll begin by illustrating the two styles with a simple example. Tests with Mock Objects Using EasyMock Driving TDD.