我无法使用 Intellitest 生成测试用例。解决问题后,我总是会收到警告说“无法在 x 运行中生成任何测试”。我需要遵循任何手动步骤吗?或者这个警告是由于代码错误或者可能是智能框架的任何限制。
请问有什么想法吗?最近几天我一直在尝试:/
我有一个名为“HolidaySetupComponent”的类。我想为此类方法“GetEmailContent(string emailtypeTag)”创建测试用例。
下面是我的代码。
public class HolidaySetupComponent
{
private string table1;
private string table2;
private string table3;
public String _CompanyId;
int _CompId;
string connectionString= ConfigurationManager.ConnectionStrings["HCMSConnectionString"].ConnectionString;
DataServices dataservice = new DataServices();
public HolidaySetupComponent()
{
dataservice.BeginProcess(connectionString);
table1 = "tblHoliday";
table2 = "tblSetupsDetail";
table3 = "tblEmailHistory";
_CompanyId = Utilities.GetCompanyId();
}
public DataSet GetEmailContent(string emailtypeTag)
{
DataSet ds = new DataSet();
int emailtypetagId = 0;
if (emailtypeTag == "NationalTab")
{
emailtypetagId = 4;
}
else { emailtypetagId = 5; }
string whereclause = "EmailType = " + emailtypetagId + "AND CompanyId =" + Utilities.GetCompanyId();
string result = dataservice.GetDataWithClause("*", "tblEmailContentCreation", whereclause, ref ds);
return ds;
}
}
public static class Utilities
{
static DataServices dataService = new DataServices();
static DataServices dataServiceAuditTrail = new DataServices();
public Utilities()
{
dataService.BeginProcess(ConfigurationManager.ConnectionStrings["HCMSConnectionString"].ConnectionString);
dataServiceAuditTrail.BeginProcess(ConfigurationManager.ConnectionStrings["vCurioAuditTrailConnectionString"].ConnectionString);
}
public static String GetCompanyId()
{
var _clientIP = HttpContext.Current.Request.Headers.GetValues("login");
string prefix = Utilities.GetPrefix(_clientIP[0]);
string _loginDetail = Utilities.GetKeyInRedis(prefix + "OtherData");
DataTable dtloginDetail = (DataTable)JsonConvert.DeserializeObject(_loginDetail, (typeof(DataTable)));
String _CompanyId = String.Empty;
if (dtloginDetail != null && dtloginDetail.Rows.Count != 0)
{
DataRow drloginDetail = dtloginDetail.Rows[0];
_CompanyId = drloginDetail["CompanyId"].ToString();
}
return _CompanyId;
}
}
当我单击“holidaySetupComponent”中存在的“GetEmailContent(string emailtypeTag)”方法上的“Run intellitest”时,我收到以下警告。
在这一步,据我了解我需要修复此警告,因此我选择了这些选项下的所有警告并应用修复。
- 对象创建 (2)
- 非仪器方法 (4)
“修复”选项在以下警告下的剩余警告被禁用,所以我“支持”这些警告
- 运行时警告
- 静态字段存储
应用这些修复后,intellitest 创建了一个工厂类“HolidaySetupComponentFactory”,用于创建“HolidaySetupComponent”的对象
public static partial class HolidaySetupComponentFactory
{
///<summary>A factory for HolidaySetupComponent instances</summary>
[PexFactoryMethod(typeof(global::HolidaySetupComponent))]
public static global::HolidaySetupComponent Create(string _CompanyId_s)
{
global::HolidaySetupComponent holidaySetupComponent
= new global::HolidaySetupComponent();
holidaySetupComponent._CompanyId = _CompanyId_s;
return holidaySetupComponent;
// TODO: Edit factory method of HolidaySetupComponent
// This method should be able to configure the object in all possible ways.
// Add as many parameters as needed,
// and assign their values to each field by using the API.
}
}
当我“抑制”警告时,还通过智能测试在 PexAssemblyInfo.cs 中添加了这些行。
[assembly: PexInstrumentAssembly("System.Configuration")]
[assembly: PexInstrumentType(typeof(Attribute))]
[assembly: PexInstrumentType(typeof(TextReader))]
[assembly: PexSuppressStaticFieldStore("System.ComponentModel.ReflectTypeDescriptionProvider", "_intrinsicTypeConverters")]
[assembly: PexSuppressStaticFieldStore(typeof(AttributeCollection), "_defaultAttributes")]
[assembly: PexSuppressStaticFieldStore("System.ComponentModel.ReflectTypeDescriptionProvider", "_attributeCache")]
[assembly: PexInstrumentAssembly("System.Xml")]
[assembly: PexSuppressExplorableEvent(typeof(global::HolidaySetupComponent))]
在此之后我得到“运行时警告”,我无法摆脱
需要帮忙!!!
谢谢