You don't need any special framework to unit test your CDI beans! Or do you mean integration testing?
googles the difference I guess?
If a given function on a service invokes another service, and that service needs to be injected, is that a unit test or an integration test?
By the strictest definition of
unit test, a unit test is a test of the unit, i.e. the class, in isolation. Now, I don't think that this kind of test is very useful at all (since it doesn't test anything about the true system requirements), and even worse it makes the code more difficult to refactor (since you have to change your tests for minor refactoring tasks).
However, in practice, I think a lot of people write unit tests that actually test the interactions between several classes, and in this case, yes,
servicesneed to be injected. But they don't need to be injected by CDI. You can inject them by calling the constructor or initializer method yourself.
I don't think
unit testis a good word to use for tests which involve the container. I call these
integration tests, though that term may also be incorrect. For this kind of test, the Weld Java SE extension will probably get you quite far, but yes, we are working on something better.
(Yes, I know a lot of people use
unit testto refer to any kind of automated test, but I think this is a very confusing usage.)
For this kind of test, the Weld Java SE extension will probably get you quite far, but yes, we are working on something better.
Cool. I found this while googling on how to implement this but I'm not sure what CDIRunner would do and the link seems to be broken.