1、对数据库进行操作的检查
(1)插入对象
检根据max Id查处数据返还为对象
String sql =
"select max(id) as maxId from person";
String sql2 = "select * from person where id = " + maxId;
String sql2 = "select * from person where id = " + maxId;
(2)更新对象
首先利用插入的操作插入一个对象,再对刚插入的对象进行更新,再根据最大的Id查询出对象进行比较
【注意】插入之后的数据,必须对数据进行清理,也就是需要做的操作包括:插入、查询比较、更新、查询比较、根据刚才的id调用删除操作。
(3)Junit4的断言加强:放弃旧的断言,使用hamcrest断言
1. assertThat
2. 使用hamcrest的匹配方法
a) 更自然
3. 示例
import org.junit.matchers.JUnitMatchers;
- a)
- assertThat( n, allOf( greaterThan(1), lessThan(15) ) );
- assertThat( n, anyOf( greaterThan(16), lessThan(8) ) );
- assertThat( n, anything() );
- assertThat( str, is( "bjsxt" ) );
- assertThat( str, not( "bjxxt" ) );
- b)
- assertThat( str, containsString( "bjsxt" ) );
- assertThat( str, endsWith("bjsxt" ) );
- assertThat( str, startsWith( "bjsxt" ) );
- assertThat( n, equalTo( nExpected ) );
- assertThat( str, equalToIgnoringCase( "bjsxt" ) );
- assertThat( str, equalToIgnoringWhiteSpace( "bjsxt" ) );
- c)
- assertThat( d, closeTo( 3.0, 0.3 ) );
- assertThat( d, greaterThan(3.0) );
- assertThat( d, lessThan (10.0) );
- assertThat( d, greaterThanOrEqualTo (5.0) );
- assertThat( d, lessThanOrEqualTo (16.0) );
- d)
- assertThat( map, hasEntry( "bjsxt", "bjsxt" ) );
- assertThat( iterable, hasItem ( "bjsxt" ) );
- assertThat( map, hasKey ( "bjsxt" ) );
- assertThat( map, hasValue ( "bjsxt" ) );
Assert.assertThat(content, JUnitMatchers.containsString(""));
本文转自 tianya23 51CTO博客,原文链接:http://blog.51cto.com/tianya23/374592,如需转载请自行联系原作者