DPascalBernard / maven-alfresco-archetypes

Automatically exported from code.google.com/p/maven-alfresco-archetypes
0 stars 0 forks source link

Unit test : spring context loaded several times #185

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
There a 2 ways to write test in alfresco :

-Extending BaseWebScriptTest when you need to test webscript. In this case, 
BaseWebscriptTest call TestWebScriptRepoServer.getTestServer(). This method  
use ApplicationContextHelper to load the context.

- Using Spring annotation on the class:
@RunWith(RemoteTestRunner.class)
@Remote(runnerClass = SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:alfresco/application-context.xml")
Context is loaded by spring, spring will not call ApplicationContextHelper to 
load the context.

Result : In a project, when you have both type of tests, context is loaded 
several times.

To fix, the issue, i wrote a customer loader (see attached file). 

@ContextConfiguration(loader = AlfrescoContextLoader.class)
public class MyTestCase {

Original issue reported on code.google.com by alexis.t...@gmail.com on 22 May 2014 at 8:44

Attachments:

GoogleCodeExporter commented 9 years ago
Another point, i think webscript test should also use annotation :
@RunWith(RemoteTestRunner.class)
@Remote(runnerClass = SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AlfrescoContextLoader.class)

The benefits is to @Autowired bean needed to setup the test data, and this will 
execute test in remote runner mode.

Original comment by alexis.t...@gmail.com on 22 May 2014 at 8:50

GoogleCodeExporter commented 9 years ago

Original comment by colum...@gmail.com on 10 Jun 2014 at 12:47

GoogleCodeExporter commented 9 years ago
Hey Alexis,

would you be interested in committing this patch and testing it?

I can give you commit access relatively easily.

Original comment by colum...@gmail.com on 10 Jun 2014 at 12:47

GoogleCodeExporter commented 9 years ago
Hi gabriele,
For sure, i can commit a patch. But i think there is another issue related to 
this one : jrebel rad devellopment.  When you want to use jrebel with the sdk 
for unit testing, you first start alfresco with mvn -Pamp-to-war,rad. This will 
load the alfresco standard context, but without spring 
alfresco/web-scripts-application-context-test.xml. Webscript test don't work in 
this case. 

In my opinion, i think we should let unit test start the context in 
RemoteServer. I made some test : you first have to start the RemoteServer main 
method with a correct classpath, then you launch test class. Test class will 
connect to RemoteServer, and start, first time, the unit test context. For now, 
i start the RemoteServer with netbeans, but it should be possible to start this 
with maven exec plugin or someting else.

Maybe you have another idea, or you already fix that ?

Original comment by alexis.t...@gmail.com on 14 Jun 2014 at 7:37