是否可以从坑覆盖范围计算中排除方法?
我的Java项目包含此类形式的类:
public final class NotInstantiableClass {
private NotInstantiableClass () {
}
// some utility functions
}
该类的构造函数无法调用。它的唯一目的是防止实例化此类。因此,该构造函数不能用单位测试覆盖。
因此,在进行坑突变测试时,该方法被列为在线覆盖结果中发现的。
有没有办法从覆盖范围计算中排除此方法?
My Java project contains a class of this form:
public final class NotInstantiableClass {
private NotInstantiableClass () {
}
// some utility functions
}
The constructor of this class cannot be invoked. Its sole purpose is to prevent instantiation of this class. Consequently, this constructor cannot be covered with unit tests.
Also consequently, when running PIT mutation tests, this method is listed as uncovered in the line coverage results.
Is there a way to exclude this method from the coverage calculation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好在公用事业课程中引发构造函数的例外:
然后,您可以通过反射测试这样的类:
测试看起来像
It's better to throw an exception from constructor in utility classes:
Then you can test such classes via reflection:
Test will be look like