0
我正在測試我的班級。我的方法返回給定策略ID的一系列保險費率和金額限制。 對於政策ID 43其財務限額爲空,其支付的保險費百分比是95.75.我試圖測試這個,但我的測試保持失敗。任何人都可以告訴我哪裏做錯了?測試比較陣列方法失敗
這是我的類
public class PatientInsuranceLimits : System.Web.UI.Page
{
String sqlConStr = ConfigurationManager.ConnectionStrings["connectionname"].ToString();
public String[] generalLimits(String policyID)
{
String []resultset = new String[2];
SqlConnection con = new SqlConnection(sqlConStr);
String sqlQuery1 = "Select InsurancePaidPercentage as iPP, FinancialLimit as fLimit from Policy where [email protected]";
SqlCommand cmd1 = new SqlCommand(sqlQuery1, con);
cmd1.Parameters.AddWithValue("@poid", policyID);
try
{
con.Open();
SqlDataReader r = cmd1.ExecuteReader();
while(r.Read()){
resultset[0] = r[0].ToString();
resultset[1] = r[1].ToString();
}
r.Close();
}
catch(Exception ex){
}
finally{
con.Close();
}
return resultset;
}
這是我的測試類
namespace _10_06_13_test
{
[TestClass()]
public class PatientInsuranceLimitsTest
{
private TestContext testContextInstance;
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
[DataSource("System.Data.SqlClient", "Data Source=servername_lab;Initial Catalog=IDKit;User ID=userid;Password=password", "mytable", DataAccessMethod.Sequential), TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\Users", "/")]
[UrlToTest("http://localhost:51063/")]
public void generalLimitsTest()
{
SurvivalHealth.PatientInsuranceLimits target = new SurvivalHealth.PatientInsuranceLimits();
string policyID = "43";
string[] expected = new string[] {"95.75"};
string[] actual;
actual = target.generalLimits(policyID);
Assert.AreEqual(expected, actual);
}
}
}
當你做Assert.AreEqual(expected [0],actual [0])時會發生什麼; –
@BobTheJanitor它仍然失敗 – kombo
對測試進行調試,看看值是什麼,它們是否匹配? –