views:

153

answers:

1

Hello experts. In my team we work both in Eclipse and Idea. That works pretty good, except for one minor issue that I can't figure out how to solve. When setting the ContextConfiguration location in our tests and running them inside Eclipse everything works like a charm:

@Test(groups = { "database" })
@ContextConfiguration(locations = {" file:src/main/webapp/WEB-INF/applicationContext.xml" })

But in my Idea env I get "could not find applicationContext" error. I need to set the location like this(project name is services):

@Test(groups = { "database" })
@ContextConfiguration(locations = {" file:services/src/main/webapp/WEB-INF/applicationContext.xml" })

The project structure is like this: parent.pom with two child poms: services.pom and other.pom. When running the test in the terminal from the service project like this:

mvn -Dtest=com.mytest.service.somepackage.TheTest test 

there are no issues. I guess that since my project structure is parent-with-two-children the need of /service is necessary(The project is created by pointing out the parent pom). Is there a way to fix this? Could you please help me with a solution. thx

+1  A: 

You use a path relative to the current working directory. Eclipse and Idea use different directories. Try to use a classpath location:

@ContextConfiguration(locations = {" classpath:/WEB-INF/applicationContext.xml" })

But I'm not sure about your classpath configuration. Typically the src/main/webapp will be copied to a target webapp directory. May be you need to configure it to contain the target webapp dir.

Arne Burmeister
Cool this worked with a modification, had to add following to my pom for it to find the context: <testResources> <testResource> <directory>src/main/webapp/WEB-INF</directory> <includes> <include>*.xml</include> </includes> <excludes> <exclude>web.xml</exclude> </excludes> </testResource> </testResources>
jakob