Unit testing Alfresco is unnecessary complex!

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2009 05:51 AM
Hi
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?
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?
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2009 05:01 PM
Welcome to the ongoing battle to improve Alfresco! Its a fact of life will always be areas of code that need reviewing, refactoring and reworking. And there is an ongoing effort in improving the product.
While I fear that if you raise this issue in a general way then it won't get very far, can I suggest that a few well targeted and explained review comments in JIRA may move forward, it sounds like you already have a few issues in mind. You could also try your hand at contributing fixes to Alfresco to make it more testable.
While I fear that if you raise this issue in a general way then it won't get very far, can I suggest that a few well targeted and explained review comments in JIRA may move forward, it sounds like you already have a few issues in mind. You could also try your hand at contributing fixes to Alfresco to make it more testable.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2011 05:10 AM
Hi
Has this been resolved, or is there a JIRA I could follow?
Thanks
Has this been resolved, or is there a JIRA I could follow?
Thanks
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2012 04:54 AM
@mrogers - I could be wrong but I think that you are running junit tests from trunk whereas we would like to run junit tests from the SDK. I was under the impression that the SDK was the recommended package to use to extend or customise the Alfresco platform?
I'm guessing that we would have to copy some files from the main distribution in order to be able to run Alfresco in embedded mode. Can you please advise which files to include?
Thanks
Mark
I'm guessing that we would have to copy some files from the main distribution in order to be able to run Alfresco in embedded mode. Can you please advise which files to include?
Thanks
Mark
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2012 05:04 AM
You should just be able to include the "SDK Embedded" project which contains all the dependencies to run alfresco in embedded mode.
The SDK contains everything you need to run either embedded or remote.
My first point remains. What in particular needs to change to make testing easier? If you have specific points then raise them in JIRA, even better contribute code and I'll merge it in for you.
The SDK contains everything you need to run either embedded or remote.
My first point remains. What in particular needs to change to make testing easier? If you have specific points then raise them in JIRA, even better contribute code and I'll merge it in for you.
