发表于: 2019-10-31 21:04:34
1 1046
今天完成的事情:
编写测试单元测试dao接口
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath*:applicationContext.xml")
public class TestAuthorMessageDao {
@Autowired
AuthorMessageDao authorMessageDao;
/*查询所有*/
@Test
public void test1(){
List<AuthorMessage> selectAll = authorMessageDao.selectAll();
System.out.println(selectAll);
}
/*2.查询对应id的内容*/
@Test
public void test2(){
AuthorMessage authorMessage = authorMessageDao.selectByPrimaryKey(1);
System.out.println(authorMessage);
}
/*3.添加一行*/
@Test
public void test3(){
AuthorMessage authorMessage = new AuthorMessage(2,1,1,"李四","感谢评价",null,null,null,null);
authorMessageDao.insert(authorMessage);
}
/*4.添加指定内容*/
@Test
public void test4(){
AuthorMessage authorMessage = new AuthorMessage();
authorMessage.setAuthorId(3);
authorMessageDao.insertSelective(authorMessage);
}
/*5.删除*/
@Test
public void test5(){
Integer authorId = 3;
authorMessageDao.deleteByPrimaryKey(authorId);
}
/*6.更新一行的选择的内容*/
@Test
public void test6(){
AuthorMessage authorMessage = new AuthorMessage();
authorMessage.setAuthorId(1);
authorMessage.setAuthorName("春天");
authorMessageDao.updateByPrimaryKeySelective(authorMessage);
}
/*7.更新一行的所有内容*/
@Test
public void test7(){
AuthorMessage authorMessage = new AuthorMessage(1,1,1,"冬天","真好看",null,null,null,null);
authorMessageDao.updateByPrimaryKey(authorMessage);
}
}
接口没啥问题
明天计划的事情:开始写Ctroller
遇到的问题:
测试单元找不到applicationContext.xml文件
发现是这里配置SqlSessionFactory时少了东西
改为
细节上的东西还是得多注意点
单元测试无法传入参数
在实体类添加构造器后解决
收获:
学会使用和生成构造器
发现接口的一些功能任务上用不到
评论