spirng项目下添加Junit测试(根据你自己的项目自行选择加载xml内容选择)

1添加pom依赖

2添加相关用到的spring相关配置文件 和 相关.properties配置文件

 

 

 

 

 

 3编写Junit测试类

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("测试完成");
    }
}

 注意事项:

 

测试成功:

 

猜你喜欢

转载自blog.csdn.net/zy103118/article/details/111313934
今日推荐