Show Menu
Cheatography

Java unit testing Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Mock

Test Class annotation
@RunWi­th(­Moc­kit­oJU­nit­Run­ner.class)
Tested Class
@Injec­tMocks
Mocked Class
@Mock
Mock w/ deep stubs
@Mock(­answer = Answer­s.R­ETU­RNS­_DE­EP_­STUBS)
 

Mockig response

Typed
when(c­las­s.m­eth­od(...)­).t­he­nRe­tur­n(...)
UnTyped
doRetu­rn(...).w­hen­(cl­ass­).m­eth­od(...)
Match primitive types
anyBoo­lean(), anyInt(), ...