小弟我最近在写单元测试,遇到一个MissingManifestResourceException的问题,找不到解决方法,请教高人!被测的类是继承于Exception类,自己写的一个异常类。比如叫:MyCustomException.
它的构造函数直接继承base()。然后重写里面的一些方法,比如ToString()方法:public override string ToString()
{
    return base.ToString();
}现在就测这个方法(不要说测这个方法没什么意义,不用测什么的话,现在就是要测它。原谅我的冒昧!),右键它使用.net
的自动生成单元测试方法功能,得到如下的测试方法:         [TestMethod()]
        public void ToStringTest()
        {
            MyCustomException target = new MyCustomException(); 
            string expected = string.Empty ; 
            string actual;
            actual = target.ToString();
            //Assert.AreEqual(expected, actual);
        }这里我先注掉AreEqual这个方法,先不管两个值最后比较是否相同,因为在调试过程中,当走到actual = target.ToString();时,就会抛个MissingManifestResourceException 的异常出来,这个异常就是我想问大家的,它是怎么出来的?怎么解决它啊?Error message 是:
Test method MyNamespace.MyCustomExceptionTest.ToStringTest threw exception:  System.Resources.MissingManifestResourceException: MissingManifestResourceException.Error Stack Trace 是:
System.Resources.ResourceManager.InternalGetResourceSet()
System.Resources.ResourceManager.InternalGetResourceSet()
System.Resources.ResourceManager.InternalGetResourceSet()
System.Resources.ResourceManager.GetString()
MyNamespace.Properties.Resources.get_StackTrace()
MyNamespace.MyCustomException.get_Message()
System.Exception.ToString()
MyNamespace.MyCustomException.ToString()
MyNamespace.MyCustomExceptionTest.ToStringTest()这里,Error Stack Trace 里的 System.Resources.ResourceManager.GetString() 是亮点。因为我发现被测试类所在的工程的Properties里是有一个Resource.Designer.cs 的文件的,但是在测试工程里没有。是不是这个原因导致的?不过我直接copy 被测试工程里的Resource.Designer.cs 到测试工程里,也是一样的fail。我试了一些方法,都不能解决这个问题。高分跪求高手帮忙解答!多谢了!