Closed Vampire closed 8 years ago
You mean, fields annotated with both @Tested and @Injectable? I remember this somewhat, but it wasn't an "officially-supported" feature. @Tested improved a lot in 1.25; to inject a non-mocked object, you simply use another @Tested field.
Really?
http://jmockit.org/changes.html says in the section Version 1.12 (Sep 21, 2014)
:
The annotations
@Tested
and@Injectable
can also be applied together to the same field. Besides causing the tested object to be partially mocked, it can also get injected into another@Tested
field, if one exists having a suitable dependency. This ability can be used in integration tests where a top-level tested object has one or more second-level tested objects as dependencies.
I just tested again:
@Tested
and @Injectable
=> Missing @Injectable
only @Tested
=> Missing @Injectable
only @Injectable
=> Test fails because instance is fully mocked
With 1.24 it was:
@Tested
and @Injectable
=> Test successful
only @Tested
=> Missing @Injectable
only @Injectable
=> Test fails because instance is fully mocked
@Tested + @Injectable is not going to be allowed anymore, as it was a premature/hackish idea. To inject non-mocked instances, use @Tested(fullyInitialized = true).
Hm, and why won't it work without fullyInitialized?
Rogério?
Isn't this at least valid as improvement request, that @Tested
are injected even without fullyInitialized
, or that @Tested
and @Injectable
can be combined to get it injected, or is there a reason not to?
Doing that would lead to multiple ways to achieve the same end result, so, no.
Oh is it? Does fullyInitilized
just look at @Tested
fields for injection? I thought fullyInitilized
does more and looks at more fields. But if that is not the case, it is clear of course.
After upgrading from 1.24 to 1.25 I get various errors, that
@Injectables
are missing that also bear the@Tested
annotation. Up to 1.24 this was possible to get real instances injected as you told me in one of the other issues I posted. 1.25 seems to break this functionality.