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