Home > Software Quality Tips > Software Testing > Building beautiful software tests around JUnit
Software Quality Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

SOFTWARE TESTING

Building beautiful software tests around JUnit


Alberto Savoia
09.17.2007
Rating: -5.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


The following is an excerpt from Chapter 7, "Beautiful Tests," taken from the book Beautiful Code.


When speaking of beautiful tests, it's hard not to think of the JUnit testing framework. Because I'm using Java, deciding to build my beautiful tests around JUnit was a very easy decision. But before I do that, in case you are not already familiar with JUnit, let me say a few words about it.

JUnit is the brainchild of Kent Beck and Erich Gamma, who created it to help Java developers write and run automated and self-verifying tests. It has the simple, but ambitious, objective of making it easy for software developers to do what they should have done all along: test their own code.

Unfortunately, we still have a long way to go before the majority of developers are testinfected (i.e., have experimented with developer testing and decided to make it a regular and important part of their development practices). However, since its introduction, JUnit (helped considerably by eXtreme Programming and other Agile methodologies, where developer involvement in testing is nonnegotiable) has gotten more programmers to write tests than anything else.* Martin Fowler summed up JUnit's impact as follows: "Never in the field of software development was so much owed by so many to so few l


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Software Testing
10 steps to acing Web app security assessments
Three software regression testing steps can perfect defect fixes
Exploring mobile layout testing, emulators and goals
Preparing for testing applications in the cloud
Hack maliciously to boost your software's security
Testing functionality, performance of mobile Web applications
Testing mobile Web applications for usability and context
Using SBTM for exploratory testing coverage problems
Web 2.0, RIAs push load testing to the max
Using session-based test management for exploratory testing

Software testing tools and frameworks
How test managers can shine in agile development: Tutorial, part two
VMLogix adds support for testing in the cloud
PushToTest taps into the cloud
Exploring mobile layout testing, emulators and goals
Liz Andrews, Marketing Manager, Altova
New tools target software QA, testing: Spring roundup
Coverity introduces build analysis tool, new Integrity Center
Agile software development tutorial: Agile project management, tools
The benefits of exploratory testing in agile environments
How to write a test strategy document

Software unit testing
Software testing deliverables: Developing a software testing strategy
Evaluating the benefits of automated software testing
Adopting continuous integration brings agility, other benefits
Tools, standards address persistent quality assurance (QA) issues
Increasing productivity with unit testing
Don't write simplistic test cases
How to develop a checklist for unit, integration and system testing
Making unit testing a priority
The Art of Debugging with GDB, DDD, and Eclipse -- Ch. 1
An approach to integration testing

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
JUnit  (SearchSoftwareQuality.com)
NUnit  (SearchSoftwareQuality.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


ines of code."

JUnit is intentionally simple. Simple to learn. Simple to use. This was a key design criterion. Kent Beck and Erich Gamma took great pains to make sure that JUnit was so easy to learn and use that programmers would actually use it. In their own words:

So, the number one goal is to write a framework within which we have some glimmer of hope that developers will actually write tests. The framework has to use familiar tools, so that there is little new to learn. It has to require no more work than absolutely necessary to write a new test. It has to eliminate duplicate effort.†

The official getting-started documentation for JUnit (the JUnit Cookbook) fits in less than two pages

Here's the key extract from the cookbook (from the 4.x version of JUnit):

When you need to test something, here is what you do:

For example, to test that the sum of two Moneys with the same currency contains a value that is the sum of the values of the two Moneys, write:

If you have any familiarity with Java, those two instructions and the simple example are all you need to get started. That's also all you need to understand the tests I will be writing. Beautifully simple, isn't it? So, let's get going.

>> Read the complete chapter, "Beautiful Tests."


Rate this Tip
To rate tips, you must be a member of SearchSoftwareQuality.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Software Design & Testing - Project Management
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2006 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts