如何进行单元测试,如果我的目标是真正的序列化? [英] How to unit test if my object is really serializable?

查看:237
本文介绍了如何进行单元测试,如果我的目标是真正的序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#2.0 NUnit测试。我有一些对象,需要序列。这些对象是相当复杂的(继承不同层次,含有大量的对象,事件和委托)。

I am using C# 2.0 with Nunit Test. I have some object that needs to be serialized. These objects are quite complex (inheritance at different levels and contains a lot of objects, events and delegates).

如何创建单元测试,以确保我的目标是安全的序列化?

How can I create a Unit Test to be sure that my object is safely serializable?

推荐答案

我这个在这里的一些单元测试的工作:

I have this in some unit test here at job:

MyComplexObject dto = new MyComplexObject();
MemoryStream mem = new MemoryStream();
BinaryFormatter b = new BinaryFormatter();
try
{
    b.Serialize(mem, dto);
}
catch (Exception ex)
{
    Assert.Fail(ex.Message);
}

可以帮助你......也许其他的方法可以更好,但这个效果很好。

Might help you... maybe other method can be better but this one works well.

这篇关于如何进行单元测试,如果我的目标是真正的序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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