java - 同型号不相等
问题描述
我正在用 JUnitTest 覆盖我的应用程序来测试我的房间并作为文档
@Test
public void writeCompanyAndReadInList() throws Exception {
// Insert the company
Company company = TestUtil.createCompany("MobOS2018");
mCompanyDao.insertCompany(company);
// Get the company
LiveData<List<Company>> byName = mCompanyDao.getCompanies("MobOS2018 AND id =1");
// Check if the two objects are equals
assertEquals("Should be equal", byName.getValue().get(0), company);
}
我的测试:
@Test
public void writeUserAndReadInList() throws Exception {
HistoryModel historyModel = TestUtil.createHistory(0,"21","3123",22-3-5L);
mHistoryDao.save(historyModel);
List<HistoryModel> byName = mHistoryDao.getAll();
Log.e("-----------i", byName.get(0).getId()+" - "+historyModel.getId());
Log.e("-----------d", byName.get(0).getDistance()+" - "+historyModel.getDistance());
Log.e("-----------t", byName.get(0).getTime()+" - "+historyModel.getTime());
Log.e("-----------c", byName.get(0).getCurrentTimeDate()+" - "+historyModel.getCurrentTimeDate());
Log.e("-----------c", byName.get(0)+" - "+historyModel);
Log.e("-----------eq", byName.get(0).toString().trim().equals(historyModel.toString().trim())+"");
assertEquals(byName.get(0), historyModel);
日志是:
E/-----------i: 0 - 0
E/-----------d: 21 - 21
E/-----------t: 3123 - 3123
E/-----------c: 14 - 14
E/-----------c: com.fitnesstracker.model.HistoryModel@e803247 - com.fitnesstracker.model.HistoryModel@5d13a74
E/-----------eq: false
我已经记录了模型的所有字段并且它们是相等的,但是我不断收到它们不相等的错误(
java.lang.AssertionError: expected:<com.myApp.model.HistoryModel@e3b4c6e>
but was:<com.myApp.model.HistoryModel@b9d3f0f>
解决方案
推荐阅读
- c - 如何将 uint8_t 值数组转换为 C 中的十六进制转储字符字符串
- aem - 如何使用 cq:editConfig 包装组件
- css - Bulma 和 Fontawesome:如何垂直和水平对齐图标?
- css - Bootstrap 4 组件具有与卡片相同的填充且没有自定义 css
- powershell - 无法将 PowerShell 变量从数组插入 Invoke-Sqlcmd 调用
- android - ion-list 不滚动且项目不可点击
- elasticsearch - 使用 multi_match 查询时如何克服 maxClauseCount 错误
- python - 为 pytrends Google Trends API 指定区域
- pandas - 熊猫数据透视表奇怪的结果
- javascript - 使用 Chrome 扩展的 ServiceNow Rest API 调用