Hi Herbert!
Just a rough idea: call
reply = bus.request(-10);
in a separate thread. Control the thread within your Unit test.
If the thread doesn't complete within a timeout intervall, kill it
and throw an exception.
Mit freundlichem Gruße
Dr. Oliver Strebel
CC RCO Treasury Control
Tiger Project
The opinions herein are my own and do not necessarily reflect those of
Dresdner Bank AG.
-----Original Message-----
From: herbert.helmstreit@xxxxxxxxxxxxxx
[
mailto:herbert.helmstreit@xxxxxxxxxxxxxx]
Sent: Mittwoch, 20. November 2002 17:28
To: junit@xxxxxxxxxxxxxxx
Subject: [junit] Testing a blocking method
Hello everybody
We have a method called String request(long timeout)
This method returns after timeout milliseconds with null result (bad case)
or after short time with a result. (good case)
We found that negative values for timeout are another reason for a failure.
They are treated like maxlong - abs(timeout), causing the method to block.
In this case an Exception should be thrown.
How can I produce a failure with jUnit, if the Exception is not thrown?
I tried it like this:
...
try
{
System.out.println("*** Request w. -10 ");
reply = bus.request(-10);
fail("negative timeout was used.");
}
catch (Exception expect)
{
System.out.println("Detected bad argument "+expect);
}
assertNull(reply);
...
JUnit hangs in the request method with a green bar until the year 2500 or
so.
How can I bring it to fail?
Thank you for any tips!
Herbert
===========================================
Dipl.-Phys. Herbert Helmstreit
Systema GmbH
Schikanederstr. 2b - Posthof
D - 93053 Regensburg
Tel.: ++941/78 39 2-36
Fax.: ++941/78 39 2-72
e-mail: herbert.helmstreit@xxxxxxxxxxxxxx
http://www.systemagmbh.de
===========================================
To unsubscribe from this group, send an email to:
junit-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
To unsubscribe from this group, send an email to:
junit-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
Thread at a glance:
Previous Message by Date:
click to view message preview
Testing a blocking method
Hello everybody
We have a method called String request(long timeout)
This method returns after timeout milliseconds with null result (bad case)
or after short time with a result. (good case)
We found that negative values for timeout are another reason for a failure.
They are treated like maxlong - abs(timeout), causing the method to block.
In this case an Exception should be thrown.
How can I produce a failure with jUnit, if the Exception is not thrown?
I tried it like this:
...
try
{
System.out.println("*** Request w. -10 ");
reply = bus.request(-10);
fail("negative timeout was used.");
}
catch (Exception expect)
{
System.out.println("Detected bad argument "+expect);
}
assertNull(reply);
...
JUnit hangs in the request method with a green bar until the year 2500 or
so.
How can I bring it to fail?
Thank you for any tips!
Herbert
===========================================
Dipl.-Phys. Herbert Helmstreit
Systema GmbH
Schikanederstr. 2b - Posthof
D - 93053 Regensburg
Tel.: ++941/78 39 2-36
Fax.: ++941/78 39 2-72
e-mail: herbert.helmstreit@xxxxxxxxxxxxxx
http://www.systemagmbh.de
===========================================
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/JjlUgA/vN2EAA/xGHJAA/5cFolB/TM
---------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
junit-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Next Message by Date:
click to view message preview
Re: Testing a blocking method
On Wednesday 20 November 2002 17:28, herbert.helmstreit@xxxxxxxxxxxxxx
wrote:
> We found that negative values for timeout are another reason for a
> failure. They are treated like maxlong - abs(timeout), causing the
> method to block. In this case an Exception should be thrown.
> How can I produce a failure with jUnit, if the Exception is not
> thrown?
I would have the method throw an IllegalArgumentException if passed a
negative value.
This is tested the way you do (except for catching
IllegalArgumentException instead of Exception to make sure it failed
exactly because of the negative argument value).
> JUnit hangs in the request method with a green bar until the year
> 2500 or so.
> How can I bring it to fail?
By checking the arguments in the method under test?
If you want to do this test-driven you may pass it a suitable negative
value. You said it waits maxlong - abs(timeout), so you could try
-maxlong + 1 as argument value.
Hope this helps,
Robert
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/JjlUgA/vN2EAA/xGHJAA/5cFolB/TM
---------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
junit-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Previous Message by Thread:
click to view message preview
Re: Testing a blocking method
Quoth herbert.helmstreit@xxxxxxxxxxxxxx:
[...]
> reply = bus.request(-10);
> fail("negative timeout was used.");
[...]
> JUnit hangs in the request method with a green bar until the year 2500 or
> so.
> How can I bring it to fail?
Rather than just testing "if the argument to request() is
negative, an exception is thrown", test the stronger statement "if
the argument to request() is negative, an exception is thrown
within two seconds (say) of the invocation". This implies having
two threads in the test: one making the erroneous call and one
waiting for up to two seconds for the other to complete.
--
Steven Taschuk | o- @
staschuk@xxxxxxxxxxxxxxx | 7O )
| " ( Hummingbird
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/CBxunD/vN2EAA/xGHJAA/5cFolB/TM
---------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
junit-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Next Message by Thread:
click to view message preview
excluded.properties
I am getting this exception whenever I run junit tests:
org.apache.commons.logging.LogConfigurationException:
java.lang.ClassCastException: org.apache.commons.logging.impl.LogFactoryImpl
Going through the junit FAQ, I modified my junit3.7.jar and added the new
excluded.properties to the jar file with following line:
excluded.9=org.apache.commons.logging.*
But, I am still getting this exception. Can anyone tell me what is that I am
doing wrong? How can I resolve this?
I am running junit3.7 with ant 1.5.1.
TIA
Catch all the cricket action. Download Yahoo! Score tracker
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/CBxunD/vN2EAA/xGHJAA/5cFolB/TM
---------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
junit-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/