JUnit 与 Rails Fixtures 并行?
我的团队有一组 POJO,我们构建它们来传递到我们的代码中并测试各种功能。例如,我们有一个包含地址信息的 Address 类。
每次我们必须将一个地址敲到一个对象上来测试某些东西时,不断地重建这个类是没有意义的。我认为像 Rails 的固定装置这样的东西会很好,但在测试树中简单地有一些合理的包和类来存储所有这些也会很好。
有什么想法吗? JUnit 有内置工具来帮助解决这个问题吗?
My team has a set of POJO's that we build up to pass into our code and test various functions. For example we have an Address class which contains address information.
It doesn't make sense to constantly rebuild this class every time we have to whack an address onto an object to test something. I am thinking that something like Rails' fixtures would be good, but simply having some sane package and class in the test tree to store all these would be nice.
Any ideas? Does JUnit have any built in tools to help with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现 xUnit Patterns 这本书对此类内容非常有帮助。您可能会发现创建方法模式很有用。
请点击链接了解有关实现和设计选择的大量详细信息。如果这没有特别帮助,请查看其他一些夹具设置模式。
I found the xUnit Patterns book very helpful for this kind of stuff. You might find the Creation Method pattern useful.
Follow the link for lots of detail about implementation and design choices. If that doesn't specifically help, check out some of the other fixture setup patterns.
JUnit 的参数化测试可能就是您想要的。您可以设置数据集合(在您的情况下是 POJO)并使用这些数据作为参数来运行测试。因此,当您添加新的示例数据时,无需重写测试。
JUnit's parameterised tests may be what you want. You can set up a collection of data (in your case, your POJOs) and run your tests using these as parameters. So you don't need to rewrite tests when you add new example data.