?????????????junit?????main???????????????????????????????????????????????
???????mybatis???????????????UserDaoImpl???????????????junitcase??λ????????′?????sourcefolder:test???檔
????????????????????
????????????????????????????????????????
1packagecn.mrf.mybatis.dao;
2
3importstaticorg.junit.Assert.*;
4
5importjava.io.InputStream;
6
7importorg.apache.ibatis.io.Resources;
8importorg.apache.ibatis.session.SqlSession;
9importorg.apache.ibatis.session.SqlSessionFactory;
10importorg.apache.ibatis.session.SqlSessionFactoryBuilder;
11importorg.junit.Before;
12importorg.junit.Test;
13
14importcn.mrf.mybatis.po.User;
15
16publicclassUserDaoImplTest{
17
18privateSqlSessionFactorysqlSessionFactory;
19
20//????????????testFindUserById?????
21@Before
22publicvoidsetUp()throwsException{
23//????sqlSessionFactory
24//mybatis???????
25Stringresource="SqlMapConfig.xml";
26
27InputStreaminputStream=Resources.getResourceAsStream(resource);
28//????????????????mybatis????????????
29sqlSessionFactory=newSqlSessionFactoryBuilder().build(inputStream);
30
31}
32
33@Test
34publicvoidtestFindUserById()throwsException{
35//????UserDao????
36UserDaouserDao=newUserDaoImpl(sqlSessionFactory);
37//????
38Useruser=userDao.findUserById(1);
39
40System.out.println(user);
41}
42
43}