sofastack / sofa-acts

ACTS is a white box testing framework based on data model drivers.
https://www.sofastack.tech/sofa-acts/docs/Home
Apache License 2.0
305 stars 86 forks source link

日志上显示的实际值和期望值一样,但实际会被判断成不一致 #13

Closed ItxiaoDz closed 5 years ago

ItxiaoDz commented 5 years ago

我测试的接口如下: Long addTeacher(ShopTeacherVO teacher) 就是简单的往数据库中插入一条记录,然后将主键值返回。 测试代码都是通过插件工具生成的。没有做修改。

测试用例的yaml配置如下:

ShopTeacherService_addTeacher_caseID_001: !!com.alipay.test.acts.model.PrepareData
  args:
    description: null
    inputArgs:
    - description: teacher
      flags:
        com.diantaoke.shop.school.base.api.domain.vo.ShopTeacherVO: {birthday: Y}
      nodeDesc: null
      nodeGroup: null
      objBaseDesc: teacher
      objBaseName: ShopTeacherVO
      objClass: com.diantaoke.shop.school.base.api.domain.vo.ShopTeacherVO
      object: !!com.diantaoke.shop.school.base.api.domain.vo.ShopTeacherVO {birthday: 1473230397944,
        createTime: 1536049910000, idcardNum: null, instId: -1, introduction: test_introduction,
        name: test, phone: '180xx24xx01', photoUrl: 'http://pic.xxxx.com/1fffff.gif',
        sex: 1, sorts: !!java.math.BigDecimal '1', summary: test_summary, teacherId: 1,
        teacherStatus: 1, updateTime: 1536049910000}
  depDataSet:
    description: null
    virtualTables: []
  description: 新增ShopTeacherService_addTeacher_TemplateCase
  expectDataSet:
    description: null
    virtualTables:
    - dataObjClazz: null
      flags: {teacher_id: C, inst_id: Y, name: Y, phone: Y, sex: Y, birthday: Y, summary: Y,
        teacher_status: Y, idcard_num: Y, photo_url: Y, introduction: N, sorts: N,
        create_time: Y, update_time: Y}
      nodeDesc: null
      nodeGroup: null
      tableBaseDesc: t_shop_teacher
      tableData:
      - {teacher_id: '1', inst_id: '-1', name: test, phone: '180xx24xx01', sex: '1',
        birthday: '1473230397944', summary: test_summary, teacher_status: '1', idcard_num: '',
        photo_url: 'http://pic.xxxx.com/1fffff.gif',
        introduction: test_introduction, sorts: '1', create_time: '1536049910000',
        update_time: '1536049910000'}
      tableName: t_shop_teacher
  expectEventSet:
    description: null
    virtualEventObjects: []
  expectException:
    description: null
    exceptionClass: null
    expectException:
      description: null
      flags: {}
      nodeDesc: null
      nodeGroup: null
      objBaseDesc: null
      objBaseName: null
      objClass: null
      object: null
    expectExceptionObject: null
  expectResult:
    description: null
    result:
      description: null
      flags: {}
      nodeDesc: null
      nodeGroup: null
      objBaseDesc: null
      objBaseName: null
      objClass: java.lang.Long
      object: 1
    resultClazz: java.lang.Long
  virtualParams:
    description: null
    params: {}

设置了期望db数据和期望结果校验。

执行单元测试后,数据库期望校验通过了,但是返回结果的校验失败了。日志如下:

2019-03-22 10:26:15,197] [] [INFO ] main <c.a.t.a.c.h.TestUnitHandler> -Checking DB, tables checked(TestUnitHandler.java:checkExpectDbData:240)
[2019-03-22 10:26:15,197] [] [INFO ] main <c.a.t.a.c.h.TestUnitHandler> -t_shop_teacher(TestUnitHandler.java:checkExpectDbData:246)
[2019-03-22 10:26:15,225] [] [INFO ] main <c.a.t.a.c.d.DBDatasProcessor> -Executing sql:select teacher_id as teacher_id,inst_id as inst_id,name as name,phone as phone,sex as sex,birthday as birthday,summary as summary,teacher_status as teacher_status,idcard_num as idcard_num,photo_url as photo_url,introduction as introduction,sorts as sorts,create_time as create_time,update_time as update_time from t_shop_teacher where (teacher_id = ?  ) ,parameters:1,(DBDatasProcessor.java:doSelectAndCompare:562)
[2019-03-22 10:26:15,232] [] [INFO ] main <c.a.t.a.c.d.DBDatasProcessor> -The comparison of the db fields is successful, table:t_shop_teacher ,key:teacher_id ,value is 1 expect vaule is 1(DBDatasProcessor.java:doSelectAndCompare:788)
.......
[2019-03-22 10:26:15,242] [] [INFO ] main <c.a.t.a.c.h.TestUnitHandler> -Checking Events(TestUnitHandler.java:checkExpectEvent:298)
[2019-03-22 10:26:15,243] [] [INFO ] main <c.a.t.a.c.h.TestUnitHandler> -Skip event check in rpc mode(TestUnitHandler.java:checkExpectEvent:379)
[2019-03-22 10:26:15,243] [] [INFO ] main <c.a.t.a.c.h.TestUnitHandler> -Checking invocation result:(DetailCollectUtils.java:appendAndLog:52)
[2019-03-22 10:26:15,243] [] [INFO ] main <c.a.t.a.c.h.TestUnitHandler> -
expect:1
actual:1(TestUnitHandler.java:checkExpectResult:275)
[2019-03-22 10:26:15,244] [] [INFO ] main <c.a.t.a.u.ObjectCompareUtil> -
expect:1
actual:1(DetailCollectUtils.java:appendAndLog:52)
[2019-03-22 10:26:15,249] [] [INFO ] main <acts-sql-logger> -Finish acts_caseId=ShopTeacherService_addTeacher_caseID_001(ActsTestBase.java:process:433)
........
java.lang.AssertionError: 
check failed, actual value:1
Expected value:1 
Expected :true
Actual   :false
 <Click to see difference>

    at org.testng.Assert.fail(Assert.java:89)
    at org.testng.Assert.failNotEquals(Assert.java:489)
    at org.testng.Assert.assertTrue(Assert.java:37)
    at com.alipay.test.acts.utils.ObjectCompareUtil.compare(ObjectCompareUtil.java:61)
    at com.alipay.test.acts.component.handler.TestUnitHandler.checkExpectResult(TestUnitHandler.java:281)
    at com.alipay.test.acts.template.ActsTestBase.check(ActsTestBase.java:531)
    at com.alipay.test.acts.template.ActsTestBase.process(ActsTestBase.java:418)

日志上显示actual value和Expected value是一样的,但是被判定为不一致了。

zhuyanli99 commented 5 years ago

ObjectCompareUtil.compare(Object target, Object expect) 这个地方本地debug看下,日志结合代码看是逻辑上看是long类型未强转为lL 比对失败原因

elseifer commented 5 years ago

你可先试试将 1 强制为 object: !!java.lang.Long 1

ItxiaoDz commented 5 years ago

@elseifer

你可先试试将 1 强制为 object: !!java.lang.Long 1

这样可以测试通过

ItxiaoDz commented 5 years ago

@zhuyanli99

ObjectCompareUtil.compare(Object target, Object expect) 这个地方本地debug看下,日志结合代码看是逻辑上看是long类型未强转为lL 比对失败原因

是的,跟踪了一下代码 ObjectCompareUtil.compare(Object target, Object expect)方法中,进入了329行的else if分支

else if (!target.equals(expect)) {
     reportStr.append("\ncheck failed, actual value:" + target + "\nExpected value:" + expect);
     return false;
}

然后Long的Long的equals方法:

public boolean equals(Object obj) {
        if (obj instanceof Long) {
            return value == ((Long)obj).longValue();
        }
        return false;
    }

因为expect是Integer类型,所以就直接返回false了。😂