我有以下测试类:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/application-context.xml" })
public class TestSanity {
@Test
public void testSanity() {
new AnotherTestClass().simpleTest();
}
}
问题是AnotherTestClass autowire字段都是null(spring上下文没有加载)。这是AnotherTestClass:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/application-context.xml" })
public class AnotherTestClass {
@Autowired
private PlayerService playerService;
@Autowired
private IPlayerSessionService playerSessionService;
@Autowired
private PlayerRepository playerRepository;
@Test
public void simpleTest() {
...
}
@Test
public void complexAndLongTest() {
...
}
事情是我测试时,AnotherTestClass中的两个测试都运行得很好。 如何让autowire字段被注入?
由于