Failed Load myclass-context.xml in junit testing
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class Myclass extends Abstr开发者_C百科actTransactionalJUnit4SpringContextTests
{
@Test
public final void testHandleRequestView() throws ServletException, IOException
{
//some testing codes
}
}
When I run junit testing for this kind of class it gave me error "Failed to load Application Context"
It search file called "Myclass-context.xml"
I don't need any configuration file for this, What is the reason for this and how do i sole this? Thanks.
You can specify context xml as part of @ContextConfiguraiton
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("Myclass-context.xml")
public class Myclass extends AbstractTransactionalJUnit4SpringContextTests
{
@Test
public final void testHandleRequestView() throws ServletException, IOException
{
//some testing codes
}
}
If you don't need a Spring context for your tests, you shouldn't have your test case extending a ContextTest.
extends AbstractTransactionalJUnit4SpringContextTests
is not required.
精彩评论