我正在尝试NUnit
在阅读CSV file
ie后将参数传递给测试
[Test, TestCaseSource(typeof(RegistrationData), "GetTestData")]
public void RegisterUserTest(RegistrationData registrationData)
{
RegisterNewUser registration = new RegisterNewUser(this.driver);
this.driver.Navigate().GoToUrl(baseURL + "/mercuryregister.php");
registration.registerNewUser(registrationData);
}
但我得到了错误:
System.InvalidCastException:无法将“RegisterUser.RegistrationData”类型的对象转换为“System.Collections.IEnumerable”.RegisterUser.UserRegistrationTest.RegisterUserTest
private RegistrationData GetTestData()
{
DataTable dt = DataTable.New.ReadCsv(@"C:\datafolder\regdata.csv");
RegistrationData registrationData = new RegistrationData();
foreach (Row row in dt.Rows)
{
registrationData.setfirstName(row["FirstName"]);
registrationData.setfirstName(row["LastName"]);
registrationData.setPhone(row["Phone"]);
registrationData.setUserName(row["UserName"]);
registrationData.setAddress1(row["Add1"]);
registrationData.setAddress2(row["Add2"]);
registrationData.setCity(row["City"]);
registrationData.setState(row["State"]);
registrationData.setPostalcode(row["Postalcode"]);
registrationData.setCountry(row["Country"]);
registrationData.setEmail(row["Email"]);
registrationData.setPassword(row["Password"]);
registrationData.setConfimPassword(row["Cpassword"]);
}
// return new RegistrationData[][] { { registrationData } };
return registrationData;
}