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?
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.