| | 36 | 如何单元测试SqlHelper.buildInsert?[[BR]] |
| | 37 | 测试SqlHelper.buildInsert(List<FieldDesc> fields, String tablename,String[] excludes);方法,需要准备fields,tablename,excludes这三个参数[[BR]] |
| | 38 | fields是数据库表的元信息,元信息依赖SimpleJdbcTemplate对象根据表名获取,我们让测试类SqlHelperTest继承之AbstractTransactionalJUnit4SpringContextTests[[BR]] |
| | 39 | 以获得applicationContext对象的引用,然后注入SimpleJdbcTemplate对象. |
| | 40 | {{{ #!java |
| | 41 | @RunWith(SpringJUnit4ClassRunner.class) |
| | 42 | @ContextConfiguration(locations = { "classpath:applicationContext.xml" }) |
| | 43 | public class SqlHelperTest extends |
| | 44 | AbstractTransactionalJUnit4SpringContextTests { |
| | 45 | |
| | 46 | @Autowired |
| | 47 | SimpleJdbcTemplate simpleJdbcTemplate; |
| | 48 | |
| | 49 | ...... |
| | 50 | } |
| | 51 | }}} |