cancel
Showing results for 
Search instead for 
Did you mean: 

Unit testing strategies for Alfresco

afielden
Confirmed Champ
Confirmed Champ

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?

4 REPLIES 4

jpotts
World-Class Innovator
World-Class Innovator

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.

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.

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.

lucastancapiano
Confirmed Champ
Confirmed Champ

Hi, you can use alfresco-tests. It's very simple to use. Only add the library dependency in your pom and write your unit test. Here you can find insights https://alfresco-tests.vige.it