问题描述
abstractclassA{}classB:A{publicbb(){}}ClassC{Aa;fun(A){}}自动生成类C的测试代码请问这个类C里面成员变量A怎么初始化??????[TestMethod()]publicvoidConstructorTest(){Ainne=null;//TODO:Initializetoanappropriatevalue//ConstructAppLoggerCtarget=CAccessor.CreatePrivate(Ainne);//TODO:ImplementcodetoverifytargetAssert.Inconclusive("TODO:Implementcodetoverifytarget");}使用自动生成的包装器没法实例化!!!!!!!!
解决方案
解决方案二:
#region附加测试属性//编写测试时,可使用以下附加属性:#regionInitTestpublicstaticstringinvokeusername;publicstaticstringinvokeuserpwd;publicstaticstringusername;publicstaticstringuserIP;publicstaticstringConnKey;publicstaticstringConnValue;publicstaticintrowCount;publicstaticDateTimeldNow;publicstaticstringLanguages;#endregion[ClassInitialize()]publicstaticvoidMyClassInitialize(TestContexttestContext){invokeusername="Nasdasdas";invokeuserpwd="jasdadasdasda";username="downmoon";userIP="10.103.33.6";ConnKey="";ConnValue="";rowCount=0;ldNow=DateTime.Now;Languages="cn";}[ClassCleanup()]publicstaticvoidMyClassCleanup(){invokeusername=null;invokeuserpwd=null;}#endregion#regionHelloWorld()的测试///<summary>///HelloWorld()的测试///</summary>[TestMethod]publicvoidHelloWorldTest(){try{PassPortWebServicetarget=newPassPortWebService();target.SecuritySoapHeaderValue=newTestAPI.PassPort.SecuritySoapHeader();target.SecuritySoapHeaderValue.InvokeUserName=invokeusername;target.SecuritySoapHeaderValue.InvokeUserPwd=invokeuserpwd;stringstr=target.HelloWorld();Console.WriteLine(str);//Console.WriteLine("Result:"+str);Assert.AreEqual(str,"Suceed!",false);}catch(Exceptionex){Assert.Fail("单元测试生成错误:"+ex.Message);////Console.WriteLine(ex.Message);}}#endregion
解决方案三:
Sorry!看错了! 你可以写两个测试方法:一个是生成实例, 一个是读取实例,