开发者社区> 问答> 正文

应用启动报 Can not load this fake sdk class 怎么解决?

应用启动报 Can not load this fake sdk class 怎么解决?

展开
收起
三分钟热度的鱼 2024-04-19 16:04:25 21 0
1 条回答
写回答
取消 提交回答
  • 解决方案1,引入pandoraboot环境。@RunWith(PandoraBootRunner.class)这样其实减慢了单测的运行速度,是违背了高效性原理的。但是相比较运行整个容器,运行pandora容器的时间大概在10s左右,还是能够容许的。那么有没有不让pandoraboot起来,纯mock的方法。我个人认为mock要比ut更优先 ,特别是有些外部依赖,经常迁移或者下线,可能改了1行代码,需要修1个小时测试用例。tair,lindorm等中间件也没有办法本地起环境进行mock,直接依赖外部资源非常不优雅。
    解决方案2,直接mock

    @RunWith(PowerMockRunner.class)@PrepareForTest({DataEntry.class})public class MockTair {    @Mock    private DataEntry dataEntry;
        @Before    public void hack() throws Exception {        //solve it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to http://gitlab.alibaba-inc.com/middleware-container/pandora-boot/wikis/faq for the solution        PowerMockito.whenNew(DataEntry.class).withNoArguments().thenReturn(dataEntry);    }        @Test    public void mock() throws Exception {        String value = "value";        PowerMockito.when(dataEntry.getValue()).thenReturn(value);        DataEntry tairEntry = new DataEntry();        //值相等        Assert.assertEquals(value.equals(tairEntry.getValue()));    }}
    
    2024-04-19 16:40:25
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
从 SDK 到编解码:视频直播架构解析 立即下载
跨平台的云服务SDK需要什么 立即下载
一个跨平台的云服务SDK需要什么 立即下载