开发者

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

开发者 https://www.devze.com 2023-01-19 20:13 出处:网络
This is my JUnit class : @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { \"WEB-INF/spring-test-config.xml\"})

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'开发者_StackOverflows failed, because the file spring-test-config.xml is not found.

My project architecture is :

  • /src/main/com/xxx/ : my source code

  • /src/main/WEB-INF/ : my config files; under this folder there is spring-test-config.xml : this file is not the final xml because it contains some tokens which replace by a Ant target. And the final result of this file is place in WebContent (deploy directory in fact) - see above.

  • /WebContent/WEB-INF/classes/com/xxx/ : my binary code

  • /WebContent/WEB-INF/spring-test-config.xml

So, how can i do to resolve this problem ?


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消