Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Testing, Testing . . .
Testing, Testing . . .

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.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Martin Fowler also discusses the importance of testing -- early and often -- as he describes "Continuous Integration". (See his article at http://www.martinfowler.com/articles/continuousIntegration.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.

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.

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.
}
}

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.

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 client and use case in mind - it's hard to keep the interface general with that requirement in mind. But your test provides another client and another use case, forcing you to think more generally about the class you are writing. On the whole I've found this shift towards test first code has improved my productivity and the quality of my work considerably.

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.


Your Feedback
dionn wrote: Martin Fowler also discusses the importance of testing -- early and often -- as he describes "Continuous Integration". (See his article at http://www.martinfowler.com/articles/continuousIntegration.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.
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.
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. } }
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.
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 client and use case in mind - it's hard to keep the interface general with that requiremen...
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.
Latest Cloud Developer Stories
Rackspace Hosting, the service leader in cloud computing, on Thursday announced its acquisition of SharePoint911, an industry leader in SharePoint consulting, training, and "JumpStart" services within SharePoint. The unification of both companies provides capabilities to deliver ...
With Cloud Expo 2012 New York (10th Cloud Expo) now under four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have techn...
Nimble, the social CRM platform has announced the launch of Nimble 2.0, billed as the “most social” CRM platform on the market today. Nimble was designed entirely with social CRM in mind and is the first social business platform that empowers companies with the ability to get clo...
2011 was a year of rapid adoption for public and private cloud services. Instant and on-demand server provisioning was the driving force behind the massive growth. On top, cloud server templates and script automation simplified application installation for simple and pre-defined ...
"Having been in the IT field for many years, I believe the cloud computing chapter in the industry is an exciting one and I am proud to be a part of it," said National Reconaissance Office (NRO) Chief Information Officer Jill T. Singer Tuesday, as it was announced that she was on...
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 Cloud Computing News
Joyent Cloud, the highest performance public cloud, and Amplify, a startup accelerator focused on su...