是否有自动测试 getter 和 setter 的 Java 单元测试框架? [英] Is there a Java unit-test framework that auto-tests getters and setters?

查看:19
本文介绍了是否有自动测试 getter 和 setter 的 Java 单元测试框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java(和其他社区,我敢肯定)是否应该测试微不足道的 getter/setter 方法有一个众所周知的争论.通常,这与代码覆盖率有关.让我们同意这是一场公开辩论,而不是在这里尝试回答.

There is a well-known debate in Java (and other communities, I'm sure) whether or not trivial getter/setter methods should be tested. Usually, this is with respect to code coverage. Let's agree that this is an open debate, and not try to answer it here.

关于使用 Java 反射自动测试此类方法的博文已经有几篇了.

There have been several blog posts on using Java reflection to auto-test such methods.

是否有任何框架(例如 jUnit)提供这样的功能?例如一个注释说这个测试 T 应该自动测试 C 类上的所有 getter/setter,因为我断言它们是标准的".

Does any framework (e.g. jUnit) provide such a feature? e.g. An annotation that says "this test T should auto-test all the getters/setters on class C, because I assert that they are standard".

在我看来,它会增加价值,如果它是可配置的,辩论"将留给用户作为一个选项.

It seems to me that it would add value, and if it were configurable, the 'debate' would be left as an option to the user.

推荐答案

Unitils 使用静态方法执行此操作assertRefEquals.

Unitils does this w/ the static method assertRefEquals.

这篇关于是否有自动测试 getter 和 setter 的 Java 单元测试框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆