The Artima Developer Community
Sponsored Link

Java Answers Forum
How much testing is too much testing?

5 replies on 1 page. Most recent reply: Jun 16, 2003 4:34 PM by E. Nielsen

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Joe Cole

Posts: 3
Nickname: joecole
Registered: May, 2003

How much testing is too much testing? Posted: May 22, 2003 7:01 PM
Reply to this message Reply
Advertisement
Hi,

I am slowly but surely evolving my programming technique. Lately I have been "bulletproofing" my code for mission critical projects. Now, does everyone turn 4 line's code into a 40 line's code by adding error checking?

Every open source project I see (I read a lot of source) has very little error checking...

let me give an example:

************************************
String string = getStringOffUser();

File file = new File(string);

doSomethingWith(file);
************************************

3 lines of simple code.

this could turn into:

String string = getStringoffUser();

if( string == null ){
erorr : {
logger.log...
show error to user
do something to resolve error
return something;
}
}

if( string.trim().length() == 0 ){
error;
}

File file = new File(file);

if( file.exists() ){
error;
}

if( file.canRead() ){
error;
}

etc etc...

does anyone else do this or am I by myself?

Joe Cole


Joesph

Posts: 1
Nickname: orions2001
Registered: Apr, 2003

Re: How much testing is too much testing? Posted: May 23, 2003 12:38 AM
Reply to this message Reply
Boss, what you are attempting to do is fantastic. But the way you are trying to achieve your purpose can be made more effecient. I am assuming that you are using JAVA. Put the entire 3 lines of the code in a try...catch block, and then handle the error. JAVA gives this unique facility so that the developer can catch errors, without having to resort to if and while conditions. Another benefit will be, your code will not catch runtime errors. but a proper try...catch block will, provided you catch the error

Try using try...catch

Bye
> Hi,
>
> I am slowly but surely evolving my programming technique.
> Lately I have been "bulletproofing" my code for mission
> critical projects. Now, does everyone turn 4 line's code
> into a 40 line's code by adding error checking?
>
> Every open source project I see (I read a lot of source)
> has very little error checking...
>
> let me give an example:
>
> ************************************
> String string = getStringOffUser();
>
> File file = new File(string);
>
> doSomethingWith(file);
> ************************************
>
> 3 lines of simple code.
>
> this could turn into:
>
> String string = getStringoffUser();
>
> if( string == null ){
> erorr : {
> logger.log...
> show error to user
> do something to resolve error
> return something;
> }
> }
>
> if( string.trim().length() == 0 ){
> error;
> }
>
> File file = new File(file);
>
> if( file.exists() ){
> error;
> }
>
> if( file.canRead() ){
> error;
> }
>
> etc etc...
>
> does anyone else do this or am I by myself?
>
> Joe Cole

Joe Cole

Posts: 3
Nickname: joecole
Registered: May, 2003

Re: How much testing is too much testing? Posted: May 23, 2003 2:16 AM
Reply to this message Reply
I know it can be made more efficient - but from the view of providing good logging, user error messages (So they actually know what went wrong) and debugging, I think it may be necessary.

I have found a way to automatically generate most if not all of this code, through the use of the template mechanism in eclipse. This means that it doesn't really take much longer - but I can be sure that it will work.

I then double check the progress by using assert statements and catching that error if need be. The errors are all serialisable through JSX2, and can be sent via email automatically to my email from the end user / client.

I know it is overboard - and things can be done very easily by catching super implementations of exceptions, but this is pretty ugly.

It just seems strange to me that no other code I have seen tries to do this in a standard fashion - its all just cast this, assume that, and run. What happens when something you don't expect happens?

Adam Duffy

Posts: 168
Nickname: adamduffy
Registered: Feb, 2003

Re: How much testing is too much testing? Posted: May 23, 2003 2:45 AM
Reply to this message Reply
> It just seems strange to me that no other code I have seen
> tries to do this in a standard fashion - its all just cast
> this, assume that, and run. What happens when something
> you don't expect happens?

That is the difference between code we write for ourselves (4 lines) and code we write for others (40 lines). If code is going to be used as part of an industrial (for want of a better word) application then you need to do the checking for null, etc.

In short, you have to expect the unexpected. Hope for the best, prepare for the worst. And so on... :)

Adam

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: How much testing is too much testing? Posted: May 23, 2003 6:01 AM
Reply to this message Reply
> Put the entire 3 lines of the code in a try...catch block, and
> then handle the error. JAVA gives this unique facility so
> that the developer can catch errors, without having to
> resort to if and while conditions.

try...catch isn't unique to JAVA. C++, C#, Python and VB.NET are 4 languages off the top of my head I can think of that also provide a try...catch mechanism to handle exceptions.

E. Nielsen

Posts: 9
Nickname: en
Registered: Feb, 2003

Re: How much testing is too much testing? Posted: Jun 16, 2003 4:34 PM
Reply to this message Reply
Try to look at AOP... www.aspectj.org

Flat View: This topic has 5 replies on 1 page
Topic: i need help... Previous Topic   http://www.blotsoft.com/">Next Topic http://www.blotsoft.com/">Topic: Very convenient programs on <a href=http://www.blotsoft.com/" border="0">

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use