SSM 创建一个测试类 Junit Test


package yourMvc;

import javax.annotation.Resource;
import org.junit.Test;
import org.apache.log4j.Logger;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.alibaba.fastjson.JSON;
import com.maimai.pojo.Student;
import com.maimai.service.IStudentService;


@RunWith(SpringJUnit4ClassRunner.class) //表示继承了SpringJUnit4ClassRunner类
@ContextConfiguration(locations = { "classpath:spring-mybatis.xml" })

public class TestStudent {
    private static Logger logger = Logger.getLogger(TestStudent.class);
    @Resource
    private IStudentService studentService = null;
    @Test
    public void studentTest() {
        Student student = studentService.getStudentById(1);
        logger.info(JSON.toJSONString(student));
    }
}

run as JUnit Test

结果

[yourMvc.TestStudent] - {"age":24,"id":1,"password":"123456","userName":"麦麦"}

 

参考博客

http://blog.csdn.net/zhshulin/article/details/37956105#

http://blog.csdn.net/zhshulin/article/details/23912615

待参考博客

http://blog.csdn.net/loginandpwd/article/details/74157210


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM