工具来写一个对象实例到C#(为单元测试) [英] Tool to write an object instance to C# (for unit testing)

查看:164
本文介绍了工具来写一个对象实例到C#(为单元测试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个方法,需要的对象的列表。该方法通常需要20个对象容易。每个对象对他们有15个左右的属性。

Say I have a method that takes a list of objects. The method will normally take 20 objects easy. Each object has 15 or so properties on them.

为单元测试这一点,我需要键入的所有20个对象,这样我可以将它们传递到我的方法。

To unit test this, I need to type out all 20 objects so that I can pass them into my method.

这是令人沮丧的时候,我可以看到什么,我需要在我的调试器监视窗口坐在那里非常好的例子。

This is frustrating when I can see perfectly good examples of what I need sitting there in my debugger watch window.

是否有工具来采取我并使其输出到C#对象?

Is there a tool to take an object that I have and make it output to C#?

注:我看到了这样一个问题:是否有工具来序列化对象到C#对象初始化code 但code它会产生不工作...

NOTE: I saw this question: Is there a tool to serialize an object to C# object initializer code? but the code it generates does not work...

我不认为我是第一个想这一点。它比我想象的更难?还是有工具,有做到这一点了吗?

I can't think I am the first to want this. Is it harder than I think? or are there tools out there that do it already?

推荐答案

我创建了一个Visual Studio插件称为的对象导出这正是这一点。你可以在C#中,JSON或XML导出对象实例。

I created a visual studio plugin called Object Exporter which does exactly this. You can export an object instance in C#, JSON or XML.

这篇关于工具来写一个对象实例到C#(为单元测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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