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:SheetsDataSheet.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
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…