Anthony
Anthony

Reputation: 71

JUnit : my XML file location in @ContextConfiguration isn't found

This is my JUnit class :

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "WEB-INF/spring-test-config.xml"})    
public class TestXXXX extends TestBase
{ ...

When I launch this test class with JUnit runner (from Eclipse), it's failed, because the file spring-test-config.xml is not found.

My project architecture is :

So, how can i do to resolve this problem ?

Upvotes: 2

Views: 10675

Answers (3)

Ricardo García
Ricardo García

Reputation: 325

Can you show all your project structure, and where is your test class placed too.

Configure directories in classpath from eclipse.

After that you can define your spring-context application file in src/resources/test directory and load it with @ContextConfiguration(locations = { "/spring-test-config.xml"}).

I hope it helps

Upvotes: 5

Michael Gower
Michael Gower

Reputation: 81

You would probably want to check your ant configuration.

I had the same problem (using Maven) and tried Ricardo's and Katie's ideas no to avail, then I put a test config file into /src/test/resources (note the subtle difference) and only then did '@ContextConfiguration(locations = { "/spring-test-config.xml"})' work. In conclusion, you probably want to go with Ricardo's idea and then check your build process.

Upvotes: 0

Ben K
Ben K

Reputation: 1

I've faced this problem before - you need to add the WEB-INF folder to your build path.

Upvotes: 0

Related Questions