单元测试问题菜鸟问题.谢谢了
要对一个类的方法进行单元测试,这个类的方法不是静态的,是不是要创建新的对象来调用方法?? 而这个类的方法涉及的参数多而且不是基本类型??怎么进行单元测试呢????单元测试 类 对象 --------------------编程问答-------------------- 可以在@BeforeClass中完成初始化 --------------------编程问答-------------------- 楼主最好能把代码贴出来
大家帮你看看 --------------------编程问答--------------------
+1 --------------------编程问答-------------------- 你看你这个方法需要多少个参数就给他传多少个呗,然后测试 --------------------编程问答-------------------- 可以采用junit测试 打个@test标签就行 前提是你需要的类和资源都要注入 --------------------编程问答--------------------
public int updateDb(String sql, Object[] objs) {
//监控sql的执行时间,debug情况下才打印
long startTime = 0;
if(ComponentConfig.debugAble)
{
startTime = System.currentTimeMillis();
}
try {
int result = qr.update(conn, sql, objs);
//监控数据库的情况,ConnMonitorable为true的时候进行监控
if (ComponentConfig.ConnMonitorable) {
if (ConnectionData.ConnMap.get(conn) != null) {
ConnectionData.ConnMap.get(conn).setLastOptTime(
mIClockImpl.getCurrentDate(true));
ConnectionData.ConnMap.get(conn).setLastOptSql(sql);
}
}
//监控sql的执行时间,debug情况下才打印
if(ComponentConfig.debugAble)
{
long EndTime = System.currentTimeMillis();
long DurationTime = EndTime - startTime;
tlog.logInfo("SQL:"+sql+"的执行时间为 "+DurationTime);
}
return result;
} catch (SQLException e) {
tlog.logError(BaseConstants.LOG_UPDATE_ERR + e.getMessage(), 1L);
return -1;
}
}
--------------------编程问答--------------------
楼主最好能把代码贴出来
大家帮你看看
+1
代码在楼上,就是测测返回值,有异常时返回-1, --------------------编程问答-------------------- 除 --------------------编程问答--------------------
public int updateDb(String sql, Object[] objs) {
// 监控sql的执行时间,debug情况下才打印
long startTime = 0;
if (ComponentConfig.debugAble) {
startTime = System.currentTimeMillis();
}
try {
int result = qr.update(conn, sql, objs);
// 监控数据库的情况,ConnMonitorable为true的时候进行监控
if (ComponentConfig.ConnMonitorable) {
if (ConnectionData.ConnMap.get(conn) != null) {
ConnectionData.ConnMap.get(conn).setLastOptTime(
mIClockImpl.getCurrentDate(true));
ConnectionData.ConnMap.get(conn).setLastOptSql(sql);
}
}
// 监控sql的执行时间,debug情况下才打印
if (ComponentConfig.debugAble) {
long EndTime = System.currentTimeMillis();
long DurationTime = EndTime - startTime;
tlog.logInfo("SQL:" + sql + "的执行时间为 " + DurationTime);
}
return result;
} catch (SQLException e) {
tlog.logError(BaseConstants.LOG_UPDATE_ERR + e.getMessage(), 1L);
return -1;
}
}
补充:Java , Web 开发