How to use ExcelData
attribute in xUnit
framework to run my test cases present in Excel. Earlier it worked as I saw related posts. But now it is not identifying as attribute.
Asked
Active
Viewed 1,822 times
1

Rakesh Arrepu
- 71
- 1
- 1
- 7
-
Please read why [a screenshot of code is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code and properly format it instead. – JeffC Aug 30 '17 at 16:28
2 Answers
1
Earlier it used to be part of the xUnit library and now it is not. You need include the files from here

Tarun Lalwani
- 142,312
- 9
- 204
- 265
-
Just adding this pointer as I've arrived at this question looking for the same thing - The above link is a 404 but I think there are enough clues in the repo at https://github.com/xunit/samples.xunit to figure it out. – Mordy May 09 '18 at 09:32
-
-
1Thanks Tarun, I'll have a look at that - I've just switched to XUnit specifically to use Excel as a test case data source so I was a bit disappointed to see that this was gone but a brief skip-read of the newer branch looks like it might be covered by OLEDB data sources (I think you can read excel with it). – Mordy May 09 '18 at 15:56
-
It says ""Microsoft.ACE.OLEDB.12.0" is not registered on the PC. What can I do to make Excel work? – Artemious May 13 '18 at 17:18
-
See if this helps? https://stackoverflow.com/questions/6649363/microsoft-ace-oledb-12-0-provider-is-not-registered-on-the-local-machine – Tarun Lalwani May 13 '18 at 17:21
0
I ended up creating an XUnit project in Visual Studio 2017 and then inherited my own data class from the TheoryData class.
[Theory(DisplayName = "Example_Test")]
[ClassData(typeof(MyDataSource))]
public void SpreadsheetDriven(testnumber, firstString, secondString)
{
Assert.AreEqual(firstString, secondString);
}
public class MyDataSource: TheoryData<int, string, string>
{
public MyDataSource()
{
Add(1, "Red", "Red");
Add(2, "Red", "Blue");
}
}
I used the EPPlus library to read the spreadsheets in to this data source and used them in my tests. In the end it all worked out pretty well (especially once I'd realised that EPPlus uses 1-based collections when it reads cells/rows/columns ;)
Here is EPPlus : https://github.com/VahidN/EPPlus.Core and this is the tutorial that got me on the road to the strongly typed data source collections : https://andrewlock.net/creating-strongly-typed-xunit-theory-test-data-with-theorydata/

Mordy
- 522
- 7
- 22