Junit unit testing and integration of Spring

Junit unit testing

Spring integration configuration junit

  • Introducing the junit JAR integrated spring (coordinates)
  • Replace the original main method to use a note Junit provided: @RunWith
  • Inform the runner spring, spring and ioc creation is based on xml or annotation: @ContextConfiguration
    • locations: Specifies the xml file location
    • Specify the location of classes where class notes
  • When using spring 5.x version, requiring junit jar package must be 4.12 or above

Examples

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:bean.xml" })
public class Test1 {

    @Autowired
    MyService myService = null;

    @Test
    public void test(){
        myService.findAll();
    }

}
Published 70 original articles · won praise 43 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_25884515/article/details/104027818