Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Next Generation Java Testing book

 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hani Suleiman
author
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic