本文介绍了对调用基类方法的方法进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的方法
I have a method that looks something like this
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("someName", this.someName);
info.AddValue("someName1", this.someName1);
base.GetObjectData(info, context);
}
如果我正在对该方法进行单元测试,是否应该保留它不变,还是应该通过某种方式对其进行重构来尝试自己测试"base.GetObjectData()"?
如何对该方法进行单元测试?
我包含了一条语句,现在可以检查参数是否为null.
If I''m unit testing this method, should I just leave it as it is or should I try and test ''base.GetObjectData()'' by iteself by refactoring it out somehow?
How would I unit test this method?
I included a statement that now checks to see if a parameter in null.
if (info == null)
{
throw new ArgumentNullException("info");
}
我进行了这样的测试
and I included a test like so
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void GetObjectData_NullParameters_ThrowsException()
{
Respondent myRespondent = new Respondent(new RespondentInformation());
SerializationInfo info = null;
StreamingContext context = new StreamingContext();
myRespondent.GetObjectData(info, context);
}
但是还没有测试的余地吗?我还能测试什么?
but isn''t there more to test? What else can I test? Shouldn''t I be testing the base.GetObjectData'' method?
推荐答案
这篇关于对调用基类方法的方法进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!