junit 四 测试死活找不到classpath
junit 4 测试死活找不到classpath
今天在项目里用junit4集成spring做测试,以前用完全没问题,但是今天用就是找不到classpath,搞得我很无语,但是现在做一个折中办法先记录下来
以前使用代码:
import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import AA.AA.Test; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath:beans.xml"}) public class T { @Autowired private Test test; @org.junit.Test public void getTest(){ test.hi(); } }
现在折中办法:
import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import AA.AA.Test; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath*:/beans.xml"}) public class T { @Autowired private Test test; @org.junit.Test public void getTest(){ test.hi(); } }
大家应该可以看出,唯一不同的是classpath的处理,这里让它递归去找beans文件。