YOUR FEEDBACK
Adobe Flex 2 - Answering Tough Questions About Enterprise Development
A Correct Person wrote: Denis Roebrt commented on the 21 Aug 2006 "Tough Que...


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP THREE LINKS YOU MUST CLICK ON


Testing, Testing . . .

Digg This!

While I was preparing for my interview with Bruce Eckel, a quote appeared in his Web log in May that said "If it's not tested, it's broken." It got me thinking about how much I actually tested the code that I wrote. Now I don't write JUnit tests for everything, but perhaps I should. To that end, here's my proposal (I'm looking forward to the royalty check):
1.   Sun should embrace the JUnit framework and include it in the Java Development Kit.
2.   Any untested methods should throw an UntestedMethodException.

If that doesn't tell you how much that download has been tested, I don't know what will. Now I appreciate that there will be developer overheads in creating test cases, but perhaps it may make the job title "Test Engineer" popular again. This will decrease the number of unemployed IT staff; everyone's happy - apart from developers.

It's time to face facts, ladies and gentlemen; we got away with it for far too long. Now it's time to change. Let me first reassure you that "change" is not a dirty word; in fact it's one of the best things that can happen to you. Thinking differently forces you to apply yourself differently; take note of the implications of that change, and create a more secure, tight, and successful way of working. You feel good, the team feels good, and then management sees it and they feel good; company profits go up, the board and the shareholders feel good. All that from one small change. Only you control your destiny so make it work for you. Insist on change.

Anyway, back to testing. The time has come to put our former ways of testing behind us and look properly at what we do. Take the following example:

public class Calc {
public Calc(){}
public add(int a, int b){
return a+b;
}
public subtract(int a, int b){
return a-b;
}
public static void main(String[] args){
Calc c = new Calc();
System.out.println(c.add(1,2));
System.out.println(c.subtract(5,2));
// ooh! It works :)
}
}

It's very easy to assume that this class has been tested and what I've been guilty of (I can only assume countless others as well; I just hope someone else confesses :-) ) is accepting in my mind that it's okay. What we really should be doing is supplying proof to everyone else that it works! I don't want JUnit tests to be optional; I want them to be mandatory! Eclipse does a nice job of creating unit tests, but it would be nice if Eclipse (or insert the IDE of your choice) could monitor the methods and create unit tests for them automatically. Then all you'd have to do is create some test data and run the tests. Easy, simple, and you'd have evidence.

It's all too easy to fall into the trap of delivering code that you think is okay, but in no time at all management is at your desk demanding to know why the application is not working. What evidence do you have with no unit tests? Effectively none. Now I openly admit that I have sat on the fence for far too long concerning this, and I think it's one of the reasons that management spits fire and loathes some IT departments. At the end of the day there is only one person who can change my predicament - me.

Let's put down our lattes/smoothies/stock options and start writing some proper unit tests, with decent test data and proper outcomes. I'm fed up with the stigma. If you want more info on JUnit, have a look at www.junit.org. There's also an article in JDJ called "Test First, Code Later" by Thomas Hammell and Robert Nettleton (Vol. 7, issue 2) that's excellent as well.

About Jason Bell
Jason Bell is founder of Aerleasing, a B2B auction site for the airline industry. He has been involved in numerous business intelligence companies and start ups and is based in Northern Ireland. Jason can be contacted at jasonbell@sys-con.com.

dionn wrote: Martin Fowler also discusses the importance of testing -- early and often -- as he describes "Continuous Integration". (See his article at http://www.mar tinfowler.com/articles/co ntinuousIntegration.html) At IronGrid, we've embraced that concept as well and followed on specifically with "Continuous Performance" which focuses on (you guessed it) performance testing at every build -- early and often. Check the whitepaper "Continuous Performance: The Next Advance in Software Development" at www.irongrid.com.
read & respond »
Jason Bell wrote: Bill, I completely agree with what you say... The source code example does show the point I was trying to get across, that people are willing to use a main() method as a valid testing case. This is seriously wrong.
read & respond »
Bill Galen wrote: public class Calc { public Calc() { } public int add( int a, int b ) { return a + b; } public int subtract( int a, int b ) { return a - b; } public static void main( String[] args ) { Calc c = new Calc(); System.out.println( c.add( 2000000000, 2000000000 ) ); System.out.println( c.subtract( 5, 2 ) ); // ooh! It works :) // -294967296 // 3 // oops! It doesn't work :( The code you don't write has the fewest bugs. // If you depend on tests, write dependable tests. } }
read & respond »
Michael Orozco wrote: I loved the article! I just recently graduated from college. I am very lucky to have a boss-(technical teacher) to take me under his wing, and show me the way to develop software. Everything begins with the test, or atleast it should. Writing the software is easy, making it work is the hard part. But, if you test the code before you write it, then putting it together ensures the stability of the code. It also helps save time in the development process. If a programmer can test his/her code first, then this will save them time debugging their code later. I use Netbeans JUnit IDE to write and test my code. I write out a class with empty methods and create JUnit tests from them. the JUnit methods are all set to a failed state, until you write your code for the method. It is somewhat of the same format as the unTestedMethod format used in the article.
read & respond »
Ben Butchart wrote: I think it is right that the secret to testing is adopting the right mind set. I agree with Kent Beck and others that the best way to write test code is to write the test before the code you are going to test. This might sound crazy at first but it makes alot of sense. First it makes you more honest. If you've already written and compiled code you tend to lose interest. The fun bit of working out how to do it and making it compile and run is over. Writing a test is boring after that. Writing the test first is just as challenging as writing the code itself though and you can be honest and imaginative thinking up test cases because you haven't invested any time or pride in what you are testing yet. Also you tend to design code to be more reusable. Usually when you design a class you have a particular ...
read & respond »
Fred Brassard wrote: It is nice to here that a developer dose admits to not testing enough. As a QA engineer that has seen development think that test all of their code, and does not need QA, this is good. With industry laying off most of their QA engineers in order to get the product out early. If they would have QA start at the specification level their product would get out the door sooner.
read & respond »
LATEST JAVA STORIES & POSTS
JavaOne 2008: A Developer's Perspective
This is my third JavaOne. Many topics were discussed, friendships were made, new partnerships were started. I must say things have changed a lot and stayed the same yet again, here are my thoughts in no particular order, bear in mind that they do not represent the opinion of my c
3rd International Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in mi
A Lightweight Approach to SOA and BPM in Java Using jBPM
SOA is mostly associated with technologies such as BPEL, SCA and Web Services. But does SOA really imply these technologies? In this session we will show how you can use the service oriented approach while staying inside the Java world. jBPM is a powerful lightweight framework th
Case Study: Java and the Mac
This is the story of a Mac application developer (okay - it's about two of them) who set out on a quest to find an application development tool based on Java so his boss would let him develop on the Mac platform, which he loved. There was only one catch - he had to find a tool th
eApps Hosting Now Offers the GlassFish Java Application Server in VPS Hosting Plans
eApps Hosting announced that the GlassFish Open Source Application Server for Java EE 5, from the GlassFish community project, is now available as a click installable application service in low cost Virtual Private Server (VPS) hosting plans. The eApps Hosting service has support
The 4 Core Principles of Agile Programming
One of the things I really enjoy at the moment is the recognition and adoption of agile programming as a fully fledged powerful way to deliver quality software projects. As its figurehead is a group of very talented individuals who have created the agile manifesto (http://agilema
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING JAVA NEWS
Five Sun Microsystems Women Honored with Prestigious Awards
Sun Microsystems, Inc. (NASDAQ:JAVA) today announced that five Sun women have been awar