File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Next Generation Java Testing book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Next Generation Java Testing book" Watch "Next Generation Java Testing book" New topic
Author

Next Generation Java Testing book

Ken Boyd
Ranch Hand

Joined: Dec 10, 2003
Posts: 329
Hello Cedric and Hani,
Welcome to Javaranch. I am using google web toolkit with RPC calls to database. Your book index has Asynchronous Testing topic. Do you think it will help me testing RPC calls to database?

Thanks


SCJP, SCWCD, SCBCD, SCJD, BB Java2 and JSP1.1
Hani Suleiman
author
Greenhorn

Joined: Nov 18, 2007
Posts: 22
Yes, it's actually very easy to do this sort of test via dependencies, we cover this quite extensively in the book (both in terms of async testing in general, and illustrating the same techniques later on with JMS).

The basic idea is to have test pairs, one for sending and one for receiving. The receiver depends on the sender, and has a timeout value so you dont end up blocking forever. In code, the test's annotation looks like @Test(dependsOnMethod="sendRequest", timeout=1000)

TestNG will run the first test (or configuration method, if its not an actual test) which will send the request. Then the second test is run, which will read the response (well, wait for it first), and verify the results. TestNG allows you to guarantee that the tests are run in that order, so you dont end up waiting for a response before you've sent the request out.
Daniel Trebbien
Ranch Hand

Joined: Jul 10, 2007
Posts: 44
This is interesting. Is there also a way to run two test methods simultaneously? For example, if one wishes to test the server-side and client-side code of a protocol implementation.

Daniel
Ken Boyd
Ranch Hand

Joined: Dec 10, 2003
Posts: 329
Thanks for your reply. I feel pretty good that your book cover async topic. I would definitely look into that in coming weeks as code is growing fast.

Thanks,
Ken
Cedric Beust
author
Ranch Hand

Joined: Oct 12, 2004
Posts: 46
Originally posted by Daniel Trebbien:
This is interesting. Is there also a way to run two test methods simultaneously? For example, if one wishes to test the server-side and client-side code of a protocol implementation.

Daniel


Yes: you can ask TestNG to run all your test methods in different threads (you configure the thread pool size in testng.xml). Here is the relevant documentation link:

http://testng.org/doc/documentation-main.html#parallel-running

However, I'm not sure I would do that in the situation you are describing, since both sides should be part of the same test method. You would probably be better off spawning the back-end part in a separate thread and wait for it in the main thread. You can also ask TestNG to abort you after a little while to make sure you won't block:

@Test(timeOut = 5000 /* 5 seconds */)
public void verifyProtocol() {
// ...
}

--
Cedric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Next Generation Java Testing book