Sunday, January 29, 2006

Mocking static methods?

This wasn't obvious to me at first, it took me a while to get why we can't mock static methods. So here it goes the reason in one line,

"Static methods aren't polymorphic, they are resolved at compile time, therefor it's not possible to use mock objects to test."

Hope this help you guys who are scratching your head like I was.... (if you are not sure about polymorphism, think of it as late binding)

btw, mock objects are great, it's one of those things that once you discovered how to use them, you wonder how you ever survived without them in the first place. There are plenty of resources on the web about them, see the documentation from easymock for a quick introduction.

done: use mock objects to help speed unit testing.



126 Comments:

At 4:10 pm, Anonymous Anonymous said...

It is possible to mock static methods by using the new Java 5 instrumentaion framework. There is a project jmockit (https://jmockit.dev.java.net/) that does exactly this.

 
At 3:30 pm, Anonymous Anonymous said...

Hi

I have tried the JMockit, and it works like a charm in Eclipse. But I am not able to use it via Maven's surfire-plugin. Anyone have any experience with this?

regards,
bdk

 
At 8:09 pm, Anonymous Anonymous said...

about jmockit & maven/surefire, you can find sample code here: http://kaczanowscy.pl/tomek/?q=node/71

in short, all you have to do is to pass additional parameters (-javaagent) to the surefire plugin

cheers
Tomek Kaczanowski

 
At 7:11 pm, Anonymous Jan Kronquist said...

Another option is PowerMock that allows static mocking, final and private and lots more without changing your buildenvironment or IDE. PowerMock extends EasyMock and also Mockito, so you don't have to learn a new API if you already use these.

 
At 10:23 am, Anonymous Anonymous said...

Yes, PowerMock seems very easy to use, but it does not work with TestNG today :-(
JMockit is good but the support for Maven is very bad. (-javaagent ??? Maven artefacts ?)
For our need PowerMock and JMockit is not adapted, so we prefer to implements utility methods for specific cases.
Like that : http://blogs.bytecode.com.au/glen/2006/10/12/doing-bytecode-kungfu-with-javassist.html

regards,
Baptiste GAILLARD

 
At 5:25 am, Anonymous Anonymous said...

[url=http://www.onlinecasinos.gd]casino[/url], also known as unsettled casinos or Internet casinos, are online versions of circadian ("buddy and mortar") casinos. Online casinos own gamblers to assess as role in and wager on casino games with the substitute quest of the Internet.
Online casinos typically tender odds and payback percentages that are comparable to land-based casinos. Some online casinos exhort on higher payback percentages with a take off it incomprehension command games, and some remonstrate upon known payout piece exposed audits on their websites. Assuming that the online casino is using an fittingly programmed unspecific in generator, catalogue games like blackjack abide an established carriage a line edge. The payout holding pursue of these games are established below the aegis the rules of the game.
Uncountable online casinos declare minus or grip their software from companies like Microgaming, Realtime Gaming, Playtech, Cosmopolitan Contrivance Technology and CryptoLogic Inc.

 
At 2:06 am, Anonymous Anonymous said...

top [url=http://www.001casino.com/]casino games[/url] brake the latest [url=http://www.casinolasvegass.com/]casino bonus[/url] free no deposit perk at the foremost [url=http://www.baywatchcasino.com/]free gratuity casino
[/url].

 
At 9:22 pm, Anonymous Anonymous said...

buy xanax cheap xanax for public speaking anxiety - xanax side effects tremors

 
At 3:08 am, Anonymous Anonymous said...

buy tramadol online buy tramadol 50mg net - tramadol addiction long term use

 
At 2:35 pm, Anonymous Anonymous said...

generic xanax do most drug test test xanax - generic form of xanax

 
At 11:18 pm, Anonymous Anonymous said...

generic xanax xanax effects testosterone - what does 1mg of xanax do

 
At 11:54 pm, Anonymous Anonymous said...

generic tramadol tramadol for dogs uses - tramadol drug test

 
At 1:07 pm, Anonymous Anonymous said...

xanax online what is xanax taken for - buy ksalol xanax

 
At 1:35 pm, Anonymous Anonymous said...

generic xanax xanax bars tumblr - long term effects xanax use

 
At 1:44 pm, Anonymous Anonymous said...

buy tramadol online buy tramadol online usa - tramadol 200 mg get high

 
At 12:48 am, Anonymous Anonymous said...

xanax online military drug test xanax - buy xanax with paypal

 
At 3:43 am, Anonymous Anonymous said...

xanax 2mg 2mg ativan vs xanax - xanax overdose do

 
At 5:57 am, Anonymous Anonymous said...

buy tramadol online buy tramadol online usa - tramadol 50 mg headache

 
At 9:45 pm, Anonymous Anonymous said...

buy tramadol online tramadol ultram side effects dogs - tramadol 50mg can you get high

 
At 2:30 am, Anonymous Anonymous said...

alprazolam price what is your xanax dosage - cheap xanax online no rx

 
At 3:43 pm, Anonymous Anonymous said...

generic xanax xanax pills yellow - peach xanax high

 
At 5:43 pm, Anonymous Anonymous said...

tramadol online pharmacy buy tramadol no prescription cheap - tramadol 200 mg no prescription

 
At 7:09 pm, Anonymous Anonymous said...

buy carisoprodol soma carisoprodol classification - buy carisoprodol online no prescription

 
At 9:23 pm, Anonymous Anonymous said...

buy tramadol in florida discount tramadol online - buy tramadol usa

 
At 5:27 am, Anonymous Anonymous said...

generic xanax does 1mg xanax feel like - xanax wiki fr

 
At 5:51 am, Anonymous Anonymous said...

buy carisoprodol carisoprodol 1050 mg - soma carisoprodol drugs

 
At 6:40 am, Anonymous Anonymous said...

buy xanax online cheap can xanax overdose kill you - cost of generic xanax without insurance

 
At 11:21 am, Anonymous Anonymous said...

buy tramadol online tramadol 50mg how many to get high - tramadol 50 mg stronger than vicodin

 
At 11:45 am, Anonymous Anonymous said...

buy tramadol online tramadol withdrawal anxiety - best place buy tramadol online

 
At 11:09 pm, Anonymous Anonymous said...

xanax online xanax for dogs - buy xanax online in canada

 
At 1:00 am, Anonymous Anonymous said...

buy tramadol cod buy tramadol online no prescription usa - illegal to buy tramadol online

 
At 1:54 am, Anonymous Anonymous said...

cheap carisoprodol carisoprodol legal status - carisoprodol us

 
At 2:27 am, Anonymous Anonymous said...

xanax without a perscription xanax hangover - xanax dosage length

 
At 3:47 am, Anonymous Anonymous said...

generic xanax long xanax urine drug test - xanax high like

 
At 7:00 am, Anonymous Anonymous said...

buy tramadol online tramadol no prescription cheap - where to buy tramadol forum

 
At 4:37 pm, Anonymous Anonymous said...

generic xanax buy xanax mastercard - xanax drug slang

 
At 1:33 am, Anonymous Anonymous said...

generic carisoprodol carisoprodol 350 mg contraindications - soma = carisoprodol tablets 350 mg

 
At 4:41 am, Anonymous Anonymous said...

buy tramadol online long does 100mg tramadol last - buy tramadol online no prescription usa

 
At 4:55 am, Anonymous Anonymous said...

buy tramadol online tramadol no prescription cheap - buy generic tramadol online

 
At 10:18 am, Anonymous Anonymous said...

where can i order xanax online xanax xr generic - what does generic xanax look like

 
At 7:45 pm, Anonymous Anonymous said...

buy discount tramadol tramadol dosage dogs 50 mg - tramadol hcl 50 mg can you get high

 
At 8:27 pm, Anonymous Anonymous said...

tramadol cheap how tramadol addiction is treated - order tramadol online overnight

 
At 8:41 pm, Anonymous Anonymous said...

buy carisoprodol somacid 350 mg carisoprodol - carisoprodol information

 
At 1:47 pm, Anonymous Anonymous said...

buy tramadol online tramadol de 50 mg para que sirve - tramadol hcl brand name

 
At 4:12 pm, Anonymous Anonymous said...

buy carisoprodol soma carisoprodol interactions - carisoprodol 350 mg strength

 
At 9:35 pm, Anonymous Anonymous said...

buy cialis online buy cialis 20mg online - buy cialis discount online

 
At 9:47 pm, Anonymous Anonymous said...

buy tramadol online tramadol 50 mg #20 - many tramadol 50 mg get high

 
At 1:11 am, Anonymous Anonymous said...

order tadalafil buy cheap cialis us - cialis dose

 
At 11:56 am, Anonymous Anonymous said...

buy tramadol online tramadol buy online florida - tramadol 50mg 100ct

 
At 2:37 pm, Anonymous Anonymous said...

xanax online clonazepam vs xanax dosage - can xanax show up drug test

 
At 1:42 am, Anonymous Anonymous said...

cialis online cialis online soft - generic cialis in usa

 
At 6:09 am, Anonymous Anonymous said...

buy xanax bars xanax generic best - xanax buy online australia

 
At 2:54 pm, Anonymous Anonymous said...

cialis online cialis online cheap no prescription - cheap cialis eu

 
At 4:48 pm, Anonymous Anonymous said...

cialis online buy cialis online mastercard - price for cialis 10mg

 
At 12:12 am, Anonymous Anonymous said...

buy xanax online xanax generic effective - xanax drug

 
At 9:49 am, Anonymous Anonymous said...

buy cialis viagra buy cialis online usa pharmacy - generic cialis legitimate

 
At 2:38 pm, Anonymous Anonymous said...

buy cialis online can buy cialis usa - cialis+online drugstore

 
At 3:37 pm, Anonymous Anonymous said...

buy cialis online buy cialis online usa no prescription - cheap cialis reviews

 
At 6:16 pm, Anonymous Anonymous said...

xanax online xanax 1 mg color - xanax dosage before mri

 
At 1:03 am, Anonymous Anonymous said...

buy cialis professional kwikmed cialis daily - cheap cialis 5mg

 
At 7:50 am, Anonymous Anonymous said...

tadalafil online order generic cialis online no prescription - cialis online 4rx

 
At 8:53 am, Anonymous Anonymous said...

buy cialis online cialis online 24 ore - buy cialis daily online

 
At 2:53 pm, Anonymous Anonymous said...

buy cialis online safely once daily cialis reviews - best price cialis 20mg

 
At 5:34 pm, Anonymous Anonymous said...

buy tramadol online cheap buy generic tramadol online - can you buy tramadol over the counter in usa

 
At 8:49 am, Anonymous Anonymous said...

learn how to buy tramdadol buy tramadol online with american express - buy 200 mg tramadol online

 
At 2:44 pm, Anonymous Anonymous said...

http://landvoicelearning.com/#51602 tramadol for purchase - tramadol dosage dental pain

 
At 8:46 pm, Anonymous Anonymous said...

learn how to buy tramdadol tramadol overnight delivery mastercard - tramadol 50 mg drug interactions

 
At 1:08 am, Anonymous Anonymous said...

20000 :) Generic Gabapentin - gabapentin no prescription http://www.neurontinonlinecheap.net/#Generic-Gabapentin, [url=http://www.neurontinonlinecheap.net/#Neurontin-Online]Neurontin Online[/url]

 
At 4:56 pm, Anonymous Anonymous said...

http://landvoicelearning.com/#51438 tramadol dosage mayo clinic - legal buy tramadol online usa

 
At 5:47 pm, Anonymous Anonymous said...

http://buytramadolonlinecool.com/#96430 100mg tramadol lot - tramadol hcl bp

 
At 11:46 pm, Anonymous Anonymous said...

buy tramadol buy tramadol no prescription 100 mg - tramadol dosage in adults

 
At 1:44 pm, Anonymous Anonymous said...

aaa!!! Topamax For Sale - topamax for sale http://www.cheaptopamaxorder.net/#cheap-topamax, [url=http://www.cheaptopamaxorder.net/#cheap-topamax]Cheap Topamax[/url]

 
At 4:42 pm, Anonymous Anonymous said...

buy tramadol tramadol addiction suboxone - tramadol high duration

 
At 6:21 pm, Anonymous Anonymous said...

order tramadol online overnight side effects of ultram tramadol - tramadol hydrochloride dosage

 
At 9:42 pm, Anonymous Anonymous said...

can you buy tramadol online take tramadol 50 mg get high - tramadol for dogs information

 
At 1:04 am, Anonymous Anonymous said...

buy tramadol online ultram side effects insomnia - what is tramadol 50mg tablets for

 
At 4:59 am, Anonymous Anonymous said...

buy tramadol online tramadol with tylenol - buy tramadol online with echeck

 
At 7:15 am, Anonymous Anonymous said...

buy tramadol tramadol for dogs in liquid - tramadol withdrawal time frame

 
At 10:55 am, Anonymous Anonymous said...

http://landvoicelearning.com/#62431 tramadol high stories - buy tramadol online prescription

 
At 4:50 pm, Anonymous Anonymous said...

http://buytramadolonlinecool.com/#61458 buy tramadol online no prescription mastercard - tramadol 50 mg headache

 
At 11:09 pm, Anonymous Anonymous said...

buy tramadol buy ultram tramadol online - buy tramadol 627

 
At 10:55 am, Anonymous Anonymous said...

order tramadol buy tramadol online illegal - tramadol hcl 93 58

 
At 1:47 pm, Anonymous Anonymous said...

2, buy propecia online no prescription - generic propecia online http://www.propeciasaleonline.net/, order propecia online no prescription

 
At 9:27 pm, Anonymous Anonymous said...

http://blog.dawn.com/dblog/buy/#blog buy tramadol online utah - tramadol hcl 50 mg headaches

 
At 3:44 am, Anonymous Anonymous said...

http://buytramadolonlinecool.com/#96430 tramadol dosage dogs pain - tramadol zydol 50mg

 
At 6:43 am, Anonymous Anonymous said...

http://buytramadolonlinecool.com/#51726 ultram or tramadol - tramadol vs hydrocodone addiction

 
At 8:50 am, Anonymous Anonymous said...

buy tramadol ways get high tramadol - tramadol withdrawal 3 days

 
At 6:38 pm, Anonymous Anonymous said...

buy tramadol without rx tramadol 627 - buy tramadol no prescription usa

 
At 12:04 am, Anonymous Anonymous said...

http://buytramadolonlinecool.com/#91646 discount code for next day tramadol - tramadol hcl good pain

 
At 1:14 am, Anonymous Anonymous said...

buy tramadol online tramadol for dogs with pancreatitis - tramadol withdrawal back pain

 
At 2:57 am, Anonymous Anonymous said...

http://landvoicelearning.com/#21906 tramadol dosage nz - us tramadol online pharmacy

 
At 10:04 am, Anonymous Anonymous said...

buy tramadol online where to buy tramadol online forum - buy tramadol 24x7

 
At 2:02 pm, Anonymous Anonymous said...

learn how to buy tramdadol tramadol 93 58 information - buy tramadol overnight delivery

 
At 7:46 pm, Anonymous Anonymous said...

http://reidmoody.com/#37982 ativan dosage back pain - ativan effexor withdrawal

 
At 9:29 pm, Anonymous Anonymous said...

lorazepam 1mg ativan side effects sedation - ativan bipolar

 
At 10:08 pm, Anonymous Anonymous said...

buy tramadol can take 3 50 mg tramadol - tramadol 50 mg how many

 
At 7:46 am, Anonymous Anonymous said...

learn how to buy tramdadol buy tramadol online us - tramadol legal to order online

 
At 12:03 pm, Anonymous Anonymous said...

ativan medication lorazepam 1mg flying anxiety - lorazepam qt prolongation

 
At 12:13 pm, Anonymous Anonymous said...

tramadol online tramadol high mg - tramadol y sus efectos secundarios

 
At 1:58 pm, Anonymous Anonymous said...

buy ativan online lorazepam 1mg how long does it last - ativan side effects how long do they last

 
At 9:35 am, Anonymous Anonymous said...

ways to buy ativan online ativan your system - side effects for ativan

 
At 3:33 pm, Anonymous Anonymous said...

buy ativan online buy ativan overnight delivery - ativan vs xanax drug test

 
At 4:55 pm, Anonymous Anonymous said...

ways to buy ativan online ativan used - ativan withdrawal and seizures

 
At 9:55 am, Anonymous Anonymous said...

http://reidmoody.com/#41572 ativan online no prescription needed - ativan and xanax taken together

 
At 4:48 pm, Anonymous Anonymous said...

buy xanax online xanax reviews - buy xanax from pakistan

 
At 5:56 pm, Anonymous Anonymous said...

buy xanax online legally does xanax drug do - xanax dosage colors

 
At 1:24 pm, Anonymous Anonymous said...

buy xanax online does xanax show up parole drug test - buy xanax online mastercard

 
At 12:37 am, Anonymous Anonymous said...

http://staam.org/#92453 best buy tramadol - tramadol 50 mg maximum dosage

 
At 12:39 am, Anonymous Anonymous said...

buy tramadol online without a prescription tramadol mixed with alcohol - what is tramadol 50mg tablets for

 
At 11:52 pm, Anonymous Anonymous said...

http://staam.org/#56821 tramadol dosage horses - tramadol 50 mg lexapro

 
At 11:55 pm, Anonymous Anonymous said...

buy cheap tramadol tramadol hcl 50mg buy - tramadol 800mg

 
At 8:32 am, Anonymous Anonymous said...

http://staam.org/#36750 tramadol hcl acetaminophen par - tramadol for dogs how long does it take to work

 
At 8:35 am, Anonymous Anonymous said...

buy tramadol online do people buy tramadol - buy tramadol online with paypal

 
At 1:36 am, Anonymous Anonymous said...

http://staam.org/#74560 tramadol 50mg dosage humans - buy tramadol ultram

 
At 1:39 am, Anonymous Anonymous said...

tramadol 50mg order tramadol with american express - buy cheap tramadol online cod

 
At 9:10 am, Anonymous Anonymous said...

buy xanax online xanax buy online mastercard - xanax overdose damage

 
At 10:20 am, Anonymous Anonymous said...

buy xanax online no prescription cheap klonopin vs xanax withdrawal - xanax and alcohol mixed together

 
At 9:25 am, Anonymous Anonymous said...

buy tramadol online tramadol addiction risk - dosage of tramadol for humans

 
At 9:27 am, Anonymous Anonymous said...

cheap tramadol buy tramadol online cheap no prescription - tramadol for sale no prescription

 
At 12:38 pm, Anonymous Anonymous said...

buy xanax bars online buy xanax online usa - order xanax online without rx

 
At 2:18 pm, Anonymous Anonymous said...

buy xanax online xanax dosage per weight - alprazolam 0 5mg germed

 
At 9:06 am, Anonymous Anonymous said...

buy xanax online xanax bars 2mg white - xanax xr oral side effects

 
At 11:10 pm, Anonymous Anonymous said...

buy xanax online percocet xanax high - xanax 2mg dose

 
At 2:46 am, Anonymous Anonymous said...

viagra cialis tadalafil cialis cialis 20mg

 
At 6:51 am, Anonymous Anonymous said...

buy tramadol tramadol hcl 50mg tab north - how many tramadol 50 mg to get high

 
At 2:43 pm, Anonymous Anonymous said...

Your own aгticle οffers confirmed usеful tο uѕ.
It’ѕ very informativе and you гeally arе certaіnly
quite wеll-informed in thiѕ rеgіon.
Yоu have got popped ouг sight in ordеr to varying thoughts about this kind
of tоpic using interestіng anԁ strong written сontеnt.


My web sіte ... ambien

 

Post a Comment

<< Home