Eclipse 插件,用于自动创建 Java 代码以重现对象的状态,以便在调试时进行快速测试
创建 Java 代码,例如:
Person person = new Person();
person.setName("name");
List<Address> addresses = new ArrayList<Address>();
Address address = new Address("Address");
addresses.add(address);
person.setAddresses(addresses);
我正在寻找一个 Eclipse 插件,用于在调试时从对象
。上下文是我想定义一些测试来验证转换器,并且当我从 WS 获取那些相当复杂的对象(带有对象列表的列表...)时,我宁愿在设置时自动获取 Java 代码一个断点并指示我要处理的对象。
多谢!!
I'm looking for a plugin for Eclipse to create Java code such as:
Person person = new Person();
person.setName("name");
List<Address> addresses = new ArrayList<Address>();
Address address = new Address("Address");
addresses.add(address);
person.setAddresses(addresses);
, from an object while debugging.
The context is that I want to define some testing to validate converters and as I get those quite complex objects (with lists of lists of objects...) to be converted from a WS, I'ld rather get the Java code automatically while setting a breakpoint and indicating the object I want to process.
Thanks a lot!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加评论作为答案,因为它很长。
是的,可以构建像您提到的那样的插件,但是纯 javabean 在 OO 中是一种味道,因此该解决方案仅适用于一小部分开发人员(这可能是没有插件可以做到这一点的原因之一) 。
如果对象树很复杂,则会出现更多问题(正如您所提到的)。插件在哪里停止生成数据?另一个问题是测试无法维护,想象一下这样的场景:您对其中一个 javabean 进行了微小的更改,然后需要重写 N 个测试来应对新的属性,尽管测试与该属性无关(这是不好的测试味道)
如果您想构建测试数据,请检查测试数据生成器模式 (TDB)。当您可以默认大多数值并且只需要更改一些特定值时,这是一个很好的方法。它也非常易于维护并且非常可读。
Adding comment as answer as it's quite long.
Yes it's possible to build a plugin like you mentioned, but pure javabeans are quite a smell in OO, so the solution would only apply to a small set of developers (and that's is possible one of the reasons why there's no plugin that does this).
There are even more issues with this (as you mentioned) if the object tree is complex. Where does the plugin stops generating the data? Another issue is that the tests wouldn't be maintainable, imagine the scenario where you do a small change in one of your javabeans, and then need to rewrite N tests to cope with the new property, although the tests have nothing to do with tha property (this is bad test smell)
If you want to build test data check the Test Data Builder Pattern (TDB). It's a good approach when you can default most of the values and you only need to change a few specific values. It's also quite maintainable and very readable.