1
我现在有这样的单元测试与StreamWriter的空隙方法的参数之一
public void BusinessMethod(object value, StreamWriter sw)
{
//Calls a private method that converts the data in `value` to a custom formatted string variable `str`
string str = myPrivateMethod(value);
//write the string to stream
sw.Write(str);
}
的方法,我想测试使用的方法,这方法提到here并准确地做同样的事情。但是,我的result
字符串作为空字符串返回。我无法更改方法签名。如何测试这种方法?我正在使用Nunit进行测试。
这是我的测试方法
[Test]
public void My_Test()
{
MyPoco dto = new MyPoco();
//set up the dto properties here
using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream))
{
sut.BusinessMethod(dto, writer);
string result = Encoding.UTF8.GetString(stream.ToArray());
}
}
什么是你试图验证精确行为? –
我想,如果在发送给'BusinessMethod'的DTO被写入流或不进行验证。这就是所有'BusinessMethod'所负责的。 – user20358
既然你的测试没有断言,它实际上并没有测试任何东西。你能提供一个包含所有相关代码的最小再现案例吗? –