java - Mockito: When is @Mock object get initialized and which constructor it calls -


i'm trying figure out how mockito working behind in order debug. wondering object @mock annotation, when initialized? like, before @before or after @before?

and if there're several different constructors, how mockito determines constructors call?

and if use jmockit @mocked instead, there different answers of questions above?

thank you!

mock objects created mockito don't call constructor or static initializer. (this achieved through objenesis in older versions of mockito, , bytebuddy in newer versions.) consequently, of fields uninitialized, , no side effects in constructors happen @ including exceptions might see thrown.

in contrast, spy objects do have constructors called. mockito default calling no-argument constructor (public or private) if don't initialize field, , can call constructor of choice inside initializer.

the order of @mock annotation initialization depends on technique use initialize mocks:


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -