Skip to content

AnnotationBasedMocking

Arthur Zagretdinov edited this page Jun 15, 2017 · 2 revisions

Annotation-based Mocking

Quick summary

  1. Use @PowerMockTestListener(AnnotationEnabler.class) at the class-level of your test to enable the annotation support.
  2. Use @Mock on a field to allow PowerMock to create and inject a mock of the same type as the field.
  3. Use @MockNice on a field to allow PowerMock to create and inject a nice mock of the same type as the fieldprivate constructor.
  4. Use @MockStrict on a field to allow PowerMock to create and inject a strict mock of the same type as the field
  5. Use @Mock("methodName") on a field to allow PowerMock to create and inject a partial mock of the same type as the field mocking only the method called methodName. This also work for @MockNice and @MockStrict.

References