Spring整合Junit5

第一步,引入相关依赖


        
            org.junit.jupiter
            junit-jupiter-engine
            5.6.2
        

        
            org.junit.platform
            junit-platform-runner
            1.6.2
        
        
            org.junit.jupiter
            junit-jupiter-api
            RELEASE
            test
        

        
            org.junit.platform
            junit-platform-launcher
            1.6.2
            test
        

        
            org.junit.jupiter
            junit-jupiter-engine
            5.6.2
            test
        

        
            org.junit.vintage
            junit-vintage-engine
            5.6.2
            test
        

        
            org.junit.jupiter
            junit-jupiter-params
            5.6.2
            test
        

        
            org.springframework
            spring-test
             5.0.9.RELEASE 
            provided
        

第二步,创建相关测试类

@ExtendWith(SpringExtension.class)
@ContextConfiguration("classpath:beans.xml")
//@SpringJUnitConfig(locations = "classpath:beans.xml")
public class MyTest2 {
    @Autowired
    private User user1;
    @Test
    public void Tg(){
        System.out.println(user1);
    }

}

其中

注解

可以由这个注解代替

 

 

 

你可能感兴趣的:(Spring,spring,java,后端)