Unit testing strategies for Alfresco

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member II

Unit testing strategies for Alfresco

Say I've developed a webscript, either client or platform side. What options do I have for unit testing what I just wrote? Bearing in mind that unit tests ideally should be very quick to run.

How do I test my code, without having to start up the whole Alfresco runtime environment? Is there some kind of test harness I can use?

I ask this question because the only way we've thought of being able to test the system, is by using Selenium. That is not a quick turnaround time, because as you know, Selenium tests drive a web browser, and it requires that the whole system is up and running.

What I'm looking for is something at a lower level, just to test my webscripts. Something very lightweight. Any thoughts?

3 Replies
Highlighted
Professional

Re: Unit testing strategies for Alfresco

Have you looked at how the SDK handles this? There are example JUnit scripts that invoke web scripts. Generate an all-in-one project, go into "integration-tests" and look under src/test/java. You can also look in the platform JAR module within that project under src/test/java.

Technically, I wouldn't call anything that requires a running Alfresco server to be a unit test. It is more of an integration test.

If you want to do true unit testing you can move your logic out of the web script and into "service classes" that you can then write JUnit tests for.

Highlighted
Active Member II

Re: Unit testing strategies for Alfresco

Thanks Jeff. You're absolutely right in saying that tests using Selenium are not 'unit tests', but in fact at the integration test level.

Yes we've got service classes to handle Web Script logic, but the problem is that often the code requires other services provided by the Alfresco platform e.g. NodeService, or DB query. I guess these services can be mocked, but I was just fishing for something already baked into the Alfresco platform, to provide a lightweight environment for testing.

Highlighted
Established Member

Re: Unit testing strategies for Alfresco

Hi @afielden 

which version of alfresco are you using? If you are using 6.2 (seems to be also working for 6.1, but can't guarantee), have a look at the following article:

https://vigeblog.altervista.org/how-to-quickly-test-a-webscript-on-alfresco/

and this library : https://github.com/flashboss/alfresco-tests-parent

They mock a lot of Alfresco Services so you don't need to Spin Up an Alfresco to do some tests.