VS Team Test: .Net Unit Testing with Excel as Data Source: Adapter Failed

后端 未结 3 642
独厮守ぢ
独厮守ぢ 2020-12-18 08:10

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

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-18 08:17

    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
    
    }
    

提交回复
热议问题