jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
464 stars 240 forks source link

1.25 breaks injection of @Tested @Injectable fields #308

Closed Vampire closed 8 years ago

Vampire commented 8 years ago

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.

rliesenfeld commented 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.

Vampire commented 8 years ago

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

rliesenfeld commented 8 years ago

@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).

Vampire commented 8 years ago

Hm, and why won't it work without fullyInitialized?

Vampire commented 8 years ago

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?

rliesenfeld commented 8 years ago

Doing that would lead to multiple ways to achieve the same end result, so, no.

Vampire commented 8 years ago

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.