Announcement Announcement Module
Collapse
No announcement yet.
Integration tests design Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Integration tests design

    Hi all,

    I am having problems designing my integration tests (i.e. tests that require an ApplicationContext). I need to make Spring cache the loaded contexts, both for efficiency, and to avoid exhausting my database connections (each test loads its own context, which includes a datasource connection pool). In order to use cached contexts, I must use the exact same locations String for all tests. However, most tests require some additional beans, or specifically don't want other beans. So, I can't think of a way to really reuse the exact same context for all tests, and in fact - this is conceptually wrong, as different tests do require different contexts.

    Here's a more concrete example. Let's say I've got several modules, with these context files:

    datasource.xml
    hibenrate.xml
    security.xml

    I would like Test1 to use datasource.xml and hibernate.xml, but not security.xml; I want Test2 to use datasource.xml and security.xml, but not hibenrate.xml, plus an additional stubs.xml file with beans I need specifically for Test2, such as a Hibernate sessionFactoryStub. But I want both Test1 and Test2 to reuse the same datasource, which is defined in datasource.xml!

    This is not a hypothetical example, it is in fact very close to the actual scenario I've got...

    I expect this to be a challenge to anyone with a non-trivial application, that wishes to write integration tests for it. I'd be happy if anyone could share their way of doing this.

    Naaman

  • #2
    just code related context/modules in your test case like this:

    Code:
    public class ExampleIntegrationTest extends AbstractTransactionalDataSourceSpringContextTests{
    
    protected String[] getConfigLocations() {
    return new String[] {"classpath*:/applicationContext.xml","hibenrate.xml","security.xml"};
    }
    	
    protected void onSetUpInTransaction() throws Exception {		
    }
    
    public void testSecurityCase1()throws Exception{
    //..
    assertEquals(result.size(), 88);
    }
    
    //bean wiring..
    
    }

    Comment


    • #3
      Thanks

      Thanks, I was not familiar with the classpath*: prefix.
      I will look into it.

      Naaman

      Comment

      Working...
      X