简体   繁体   English

Eclipse插件,用于自动创建Java代码以重现对象的状态,以便在调试时进行快速测试

[英]Eclipse plugin for creating Java code automatically to reproduce the state of an object for fast testing while debugging

I'm looking for a plugin for Eclipse to create Java code such as: 我正在寻找Eclipse的插件来创建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);

, 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. 上下文是我想定义一些测试来验证转换器,并且当我从WS转换那些相当复杂的对象(带有对象列表的列表...)时,我宁愿在设置时自动获取Java代码断点并指示我要处理的对象。

Thanks a lot!! 非常感谢!!

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). 是的,有可能像您提到的那样构建一个插件,但是纯Javabeans在OO中颇具味道,因此该解决方案仅适用于一小部分开发人员(这可能是没有插件执行此操作的原因之一) 。

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) 另一个问题是测试将无法维护,请设想一下您在其中一个javabeans中进行了少量更改,然后需要重写N个测试以应对新属性的情况,尽管测试与tha 没有任何关系。属性(这是不好的测试气味)

If you want to build test data check the Test Data Builder Pattern (TDB) . 如果要构建测试数据,请检查“ 测试数据构建器模式(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. 它也非常易于维护并且可读性强。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM