I am trying to do Unit Testing with Excel as data source. I am getting the following exception. How do we correct it?
The unit test adapter failed to
I faded a same task today. And after some headaches I was able to solve without app.config:
[TestMethod]
[DataSource("System.Data.OleDB",
@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Sheets\DataSheet.xlsx; Extended Properties='Excel 12.0;HDR=yes';",
"Sheet1$",
DataAccessMethod.Sequential
)]
public void ChangePasswordTest()
{
//Arrange
//Act
//Assert
}
If you use excel files as resources in your testproject, you have to set the Copy to Output Directory property of the file to Copy always
or Copy if newer
. And add the DeploymentItem
attribute to your test:
[TestMethod]
[DataSource("System.Data.OleDB",
@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=.\DataSheet.xlsx; Extended Properties='Excel 12.0;HDR=yes';",
"Sheet1$",
DataAccessMethod.Sequential
)]
[DeploymentItem(".\DataSheet.xlsx")]
public void ChangePasswordTest()
{
//Arrange
//Act
//Assert
}