首页 > 解决方案 > 使用 Java 和 Mocking 测试在 Azure 存储中测试实体

问题描述

很久以来,我一直在寻找一种方法来测试Azure 表存储中文件中的实体(添加属性、值..) 。例如,在向实体添加属性后,我想通过测试检查属性是否成功添加(完全使用模拟测试),但问题是我不想在中的Azure 存储中进行测试一个模拟器,我只想在本地测试它。我没有办法做到这一点。

TableServiceClient tableServiceClient  = mock(TableServiceClient.class);
TableClient tableClient = mock(TableClient.class);
TableEntity tableEntity = mock(TableEntity .class);
properties is a Hash map of properties and values
when(tableEntity.addProperties(properties)).thenCallRealMethod();

when(tableEntity.getProperty(Mockito.anyString())).thenCallRealMethod();
doNothing().when(tableServiceClient.createTableIfNotExists(Mockito.anyString());
when(tableServiceClient.getTableClient(Mockito.anyString()).thenReturn(tableClient);

标签: javaazuremockitocloudazure-storage

解决方案


推荐阅读