AnsweredAssumed Answered

Unit testing Alfresco is unnecessary complex!

Question asked by calle on Jan 7, 2009
Latest reply on Mar 8, 2012 by mrogers
I normally write unit tests to keep the quality of my code in development and for regression using (standard) frameworks like JUnit and JMock. When developing Alfresco extensions I often find it unnecessary hard to write them in a good way. One of the fundamental features unit testing brings is separation of concerns and the declaration of functionality as interfaces. A unit test should be isolated to a single piece of code or class and it usually requires that your are able to inject dependencies or stub them somehow.

In parts of the Alfresco code interfaces are not used (I think this is especially remarkable in many basic service beans) and dependency injection is almost never used (except the one provided by Spring which normally is on a higher level than required in a unit test). Many JSF-related classes directly uses the FacesContext class which has static dependencies which are very hard to get rid of in a unit test. Why not consider injecting the FacesContext object? Why not use factories to instantiate objects to avoid class-level dependencies?

My point is that small changes to the design would give great return on the ability to ensure quality by unit testing.

What is your thoughts on this?