Add Junit test under spirng project (choose to load xml content according to your own project)

1 add pom dependency

2 Add related spring related configuration files and related .properties configuration files

 

 

 

 

 

 3 write Junit test class

 

 

package com.app.dev.paas;


import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations ={"classpath*:/conf/Junit-databaseConfig.xml","classpath*:/conf/Junit-spring-placeholder.xml", "classpath*:/conf/Junit-Userdao.xml"
,"classpath*:com/yqbsoft/*/**/cache/springxml/applicationContext-service.xml"})
@WebAppConfiguration
public class JUnitTester {
    @Autowired
    UmUserMapper umUserMapper;
    @Autowired
    DisCache disCache;

    @BeforeClass
    public static void init(){
       // ApplicationContext content = new ClassPathXmlApplicationContext("classpath:*/applicationContext.xml");
        //osOAuthEnvService = content.getBean(OsOAuthEnvService.class);
    }

    @Test

    public void testPutOne() throws InterruptedException {
        List<UmUser> users= umUserMapper.query(null);
       String var= disCache.get("OsOAuthEnv-oauthEnvMat");
     System.out.println("测试完成");
    }
}

 Precautions:

 

testing successfully:

 

Guess you like

Origin blog.csdn.net/zy103118/article/details/111313934