开发者

Unable to autowire in JUnit tests via Ant - looks like @RunWith(SpringJUnit4ClassRunner.class) isn't working

My test case looks something like this:

@RunWith(SpringJUnit4ClassRunner.clas开发者_运维知识库s)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
public class AbstractDatabaseTestCase extends AbstractTestCase {

    @Autowired
    private SessionFactory sessionFactory;

}

For some reason when I run it locally on my computer either through Eclipse (using Junit4 test runner) or using ant (both in eclipse, or just in terminal), everything works fine and the sessionFactory gets injected correctly.

When this code is on a server (Hudson), either running it through Hudson or in the console by doing ant test (test is the target to build and run the junit tests), the sessionFactory isn't injected and it looks like Autowiring isn't working. I looked at the stack trace from the nullpointerexception and noticed that it isn't using the SpringJUnit4ClassRunner even though i have it in the @RunWith annotation (on my local computer it does use it). Any ideas why? I guess it's not autowiring because it's not using SpringJUnit4ClassRunner.

Thanks

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜