如何为私有最终匿名类编写testng测试用例

How to write testng testcase for private final anonymous class

提问人:Keerthi Senthil 提问时间:6/15/2023 最后编辑:Keerthi Senthil 更新时间:6/16/2023 访问量:28

问:

private final SampleFormatter sampleFormatter = new SampleFormatter() {

    @Override
    public String formatDouble (int tag, double Value, int pre) { 
        if (Double.isNaN(Value)) {
            return "NaN";
        } 
        if (Value == 0.0D) {
            return "0";
        } else {
            return df.format(Value);
        }
    }

}

这里示例格式化程序是一个接口,它的方法在这里实现。

如何通过编写 testng 测试用例来获得这种格式 Double() 方法的覆盖率。

junit mockito testng final private-methods

评论

0赞 Lesiak 6/15/2023
您发布的代码中没有私有的 final 方法。
0赞 Keerthi Senthil 6/16/2023
对不起,它不是一个私有的最终方法,我误解了它,它是一个私有的最终匿名类。
0赞 Lesiak 6/16/2023
通过使用此私有字段的公共方法进行测试,或使用(包私有)命名类。如果覆盖率是你的目标,我会选择后者。虽然可以通过反射进入这个领域,但它远非优雅 - 你的测试会比被测类更复杂。

答: 暂无答案