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

posted @ 2017-07-09 19:08  败草麦麦  阅读(5974)  评论(0编辑  收藏  举报