发表于: 2017-05-13 23:24:07

2 1093


【说明】今天主要是把dao层的一些类给写出来一些,除了简单的增删查改,还有很多业务方法,貌似可以不写service层,给弄得简单点。

一:今日完成

1)先是junit 测试

接下来写一个categoryDao 类的方法测试,主要是一些增删查改的方法

结果运行之后只通过了两个方法

看看问题所在

应该是junit 的方法执行顺序问题

看了看junit是否可以指定顺序

答案是可以的

有三个,推荐的是一个,为什么呢

MethodSorters.NAME_ASCENDING (推荐) 
按方法名称的进行排序,由于是按字符的字典顺序,所以以这种方式指定执行顺序会始终保持一致; 
不过这种方式需要对测试方法有一定的命名规则,如 测试方法均以 testNNN 开头(NNN 表示测试方法序列号 001-999)

确实是可以的,不过我后来发现这个其实也是通过方法名字来指定的。

还有就是除了用 syso 输出信息之外

还可以用Logger ,但是我看到了jdk 自己就提供了一个简单的日志功能 ,就顺手玩了玩

发现也挺简单的

需要导入包 java.util.Logger 这个类

然后使用就是了 ,也可以指定输出级别,输出格式 ,输出位置等 信息。

好了,后来改了一些代码之后就可以运行了

贴出代码

package com.ljl.test;
//这是一个静态包含(static),是 JDK5 中新增添的一个功能
import static org.junit.Assert.*;

public class CategoryDAOTest {
private CategoryDAO categoryDAO= new CategoryDAO();
private Category category = new Category();
private static final Logger LOG = Logger.getLogger("CategoryDAOTest");
@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

@Test
public void testGetTotal() {
assertEquals(17, categoryDAO.getTotal());
//fail("Not yet implemented");
}

@Test
public void testAdd() {
category.setId(10);
category.setName("haha");
try {
categoryDAO.add(category);
assertNotNull(categoryDAO);
} catch (Exception e) {
// TODO: handle exception
}
//fail("Not yet implemented");
}

@Test
public void testUpdate() {
category.setId(11);
category.setName("nana");
categoryDAO.update(category);
assertNotNull(categoryDAO);
//fail("Not yet implemented");
}

@Test
public void testDelete() {
categoryDAO.delete(10);
categoryDAO.delete(11);
assertNotNull(categoryDAO);
//fail("Not yet implemented");
}

@Test
public void testGet() {
category=categoryDAO.get(60);
System.out.println(category.getId());
System.out.println(category.getName());
//fail("Not yet implemented");
}

@Test
public void testList() {
List<Category> testList = new ArrayList<Category>();
testList = categoryDAO.list(0, 3);
System.out.println(testList);
LOG.info("" + testList);
assertNotNull(testList);
//fail("Not yet implemented");
}

@Ignore
public void testListIntInt() {
fail("Not yet implemented");
}

}

二:明日计划

把剩下的复杂的业务方法给写完

三:疑难问题

感觉没有原型图去设计查表语句会很没思路的。凭空想呢

四:思考总结

现在还没有用框架,简单的javabean貌似就可以给实现了


返回列表 返回列表
评论

    分享到