JUnit 与 Rails Fixtures 并行?

发布于 2024-09-01 20:14:39 字数 215 浏览 4 评论 0原文

我的团队有一组 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

¢好甜 2024-09-08 20:14:39

我发现 xUnit Patterns 这本书对此类内容非常有帮助。您可能会发现创建方法模式很有用。

通过调用隐藏在意图显示名称后面构建即用对象的机制的方法来设置测试装置。

请点击链接了解有关实现和设计选择的大量详细信息。如果这没有特别帮助,请查看其他一些夹具设置模式。

I found the xUnit Patterns book very helpful for this kind of stuff. You might find the Creation Method pattern useful.

Set up the test fixture by calling methods that hide the mechanics of building ready-to-use objects behind Intent Revealing Names.

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.

‖放下 2024-09-08 20:14:39

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文