This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Testing and the fly likes Junit test for synchronized method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Junit test for synchronized method" Watch "Junit test for synchronized method" New topic
Author

Junit test for synchronized method

Maria Laxmi
Ranch Hand

Joined: Aug 08, 2008
Posts: 40
Hi,

Is there a good way to test that a method is synchronized in a JUnit test? I have used synchronized method for J2EE application.

Thanks,
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Wouldn't you just test it like any other method?
Maria Laxmi
Ranch Hand

Joined: Aug 08, 2008
Posts: 40
My concern is to test when multiple threads try to call synchronized method at the same time. Is there any way we can catch this scenario in Junit Testcase?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Sure; set up a bunch of threads and have them call it. But that seems like unit-testing the "synchronized" keyword to me.
 
jQuery in Action, 2nd edition
 
subject: Junit test for synchronized method
 
Similar Threads
how to test void method.
test geter and setter
naming conventions for junit 4.0
Ant 1.7 + Junit 4 problems
Lock question!