本文介绍了如何在单元测试中模拟自定义类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Xunit.net对应用程序服务进行单元测试。
由于以下声明,我的单元测试用例未得到部分执行:
StringCipher stringCipher = new StringCipher();
StringCipher是我编写密码加密和解密逻辑的类。
即使它进入StringCipher类的构造函数,但在构造函数中抛出异常:
I am doing the unit testing of application service using Xunit.net.
My unit test case is not getting partially executed because of following statement:
StringCipher stringCipher = new StringCipher();
StringCipher is class in which I have written the logic for password encryption and decryption.
Even it goes inside the constructor of StringCipher class but throwing exception inside the constructor:
public class StringCipher
{
private readonly byte[] _initVectorBytes = null;
private const int KeySize = 256;
public StringCipher()
{
_initVectorBytes = Encoding.ASCII.GetBytes(ConfigurationManager.AppSettings["PasswordEncryptionKey"]);
}
}
请让我知道如何解决这个问题问题?
Please let me know how can I resolve this issue?
推荐答案
这篇关于如何在单元测试中模拟自定义类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!