cancel
Showing results for 
Search instead for 
Did you mean: 

Unit testing server side javascript

akoudrin
Champ in-the-making
Champ in-the-making
I'm about to start development on Alfresco 4.2.c using the existing Maven setup. I anticipate mostly working with Share. Furthermore, I anticipate most of development to be on javascript, both server and client side.

I'm currently looking at unit testing javascript. On client side, I've found Jasmine running PhantomJS to be good. However, I'm struggling to find and setup javascript unit testing for server side. At the moment it looks like doing a more of an end-to-end integration tests is the only feasible solution.

How has Alfresco Share done this kind of unit testing? What would you suggest a developer of new features, like me, does?
9 REPLIES 9

zladuric
Champ on-the-rise
Champ on-the-rise
For what it's worth, the furthest that I've got to is, I've built tests for my RESTful backend interfaces - just calling the POST/PUT/GET/DELETE/GET on my scripts and checking if everything is working as expected. I don't see how unit testing could be implemented, but please post back here if you find a way.

akoudrin
Champ in-the-making
Champ in-the-making
Yes, that's one of the possibilities for integration testing. What we really want, with so much server side javascript, is to have lots of unit tests to cover our code close to 100%.

zladuric
Champ on-the-rise
Champ on-the-rise
Hmm. I usually wrap everything in the controller in at least a "main" method. You could, perhaps, separate most of the controller code to a *.lib.js file, define some of your own global vars and include the lib.js file in a test version?

So your testController.js file looks like this (and you call it via that command servlet, not as a web script).
<javascript><import resource="classpath:ctrl.lib.js">
var companyhome = "fakecompanyhomeobject"
var document = fakedocument;
var args = { site: "fakeSite", nodeRef: "fakeNodeRef"};
main();
</javascript>

And your regular controller just holds the import statement and main().

Now that I've written it, it sounds kind of clumsy, but at least it's a start, right?

akoudrin
Champ in-the-making
Champ in-the-making
Ideally I'd like to find a framework to streamline writing lots of tests. Similar to Jasmine/PhantomJS framework.

zladuric
Champ on-the-rise
Champ on-the-rise
Let us know when you do Smiley Happy

zladuric
Champ on-the-rise
Champ on-the-rise
Hmm, can you find something useful here?
http://www.springsurf.org/sites/1.0.0.CI-SNAPSHOT/testapidocs/org/springframework/extensions/webscri...

Alfresco webscripts are done on springframework webscripts package.

akoudrin
Champ in-the-making
Champ in-the-making
So do Alfresco Share developers look at this forum? Rather than trying to guess I'd actually like to get their answer to this. Or perhaps some could point me to the more appropriate forum?

ddraper
World-Class Innovator
World-Class Innovator
I'm probably one of the very few Share developers to actually look at the Spring Surf forums, and I mostly just respond telling them to directly questions to the Alfresco forum. The honest answer is that up until now we haven't done a great deal of automated unit testing on Alfresco Share. There is an automated FVT suite within Surf that is based around TestNG but that is just for testing the basic Surf functionality. We are now starting to make a more concerted effort to automate the testing of Share but that does not really involve JavaScript unit tests but rather a more functional test approach. We do have Dojo DOH based unit testing on the new widget suite that we are developing though.

akoudrin
Champ in-the-making
Champ in-the-making
Great. Thank you for that honest answer. That's what I gathered in my preliminary web research too. I'll probably stick to our functional end-to-end test idea.