2

Can someone tutorial me how to create DataSource from Excel File linked wih Unit Test in VS2013? In VS2010 it was possible to open Project -> Test View and then Properties. Now that option is not possible. I tried MSDN help and so on but I cant do that. I would like to reach sh like here http://msdn.microsoft.com/pl-pl/library/testy-jednostkowe-w-visual-studio.aspx between image 16 and 17. Thank you for help

I know how Create new Data source but I do not know how to use it in [DataSource()]

[TestClass()]
public class OperationsTests
{
    private TestContext context;

    public TestContext TestContext
    {
        get { return context; }
        set { context = value; }
    }

    [DeploymentItem("1.xls")]
    [DataSource("System.Data.Odbc", @"Dsn=Excel Files;dbq=.\1.xls;defaultdir=.;driverid=790;maxbuffersize=2048;pagetimeout=5", "Arkusz1$", DataAccessMethod.Sequential)]
    [TestMethod()]
    public void AddTest()
    {
        Operations target = new Operations();
        int a = Int32.Parse(context.DataRow["A"].ToString());
        int b = Int32.Parse(context.DataRow["B"].ToString());
        int expected = Int32.Parse(context.DataRow["Wynik"].ToString());             
        int actual;                         
        actual = target.Add(a, b);          
        Assert.AreEqual(expected, actual);  
    }
}
mikroice90
  • 137
  • 1
  • 9
  • 1
    May be here http://stackoverflow.com/questions/22538340/data-driven-unit-test-from-excel-spreadsheet http://stackoverflow.com/questions/10684441/vs-team-test-net-unit-testing-with-excel-as-data-source-adapter-failed – Yuliia Ashomok Sep 19 '14 at 06:35
  • Thanks, i saw that page earlier but when i added DeploymentItem and DataSource from finger and RunTests nothing happened. – mikroice90 Sep 19 '14 at 07:00
  • Please add some code to your question. – Yuliia Ashomok Sep 19 '14 at 07:15
  • Try to Debug your test. in VS 2013: TEST -> Debug -> Selected Test. It looks like failure occurs before reaching Assert.AreEqual – Yuliia Ashomok Sep 19 '14 at 07:44
  • Do you set your context before using? – Yuliia Ashomok Sep 19 '14 at 07:46
  • Ok i corrected sth and know it said Cannot connect to data source. Should i create DataSource? – mikroice90 Sep 19 '14 at 07:50
  • It can be different reasons of this error: Access denied, File Not Exists etc. Please get Message of your exception. For do it use try-catch statement. – Yuliia Ashomok Sep 19 '14 at 07:57
  • Can you tell me if creating Data Source by Project - New Data SOurce is nessesery? About error : in the MSDN library, Error details[IM002][Microsoft][ODBC Driver Manager] Cannot fint data source name, and default driver didnt define – mikroice90 Sep 19 '14 at 08:01
  • http://forums.asp.net/t/1040141.aspx?Data+source+name+not+found+and+no+default+driver+specified+When+the+website+was+published+but+not+error+when+I+run+it+in+debug+mode+VS+NET+2005+ – Yuliia Ashomok Sep 19 '14 at 08:05
  • Sorry that didnt help me... i created a new project. i copied Operation class and OperationTests class and now i have a problem with context.DataRow everyone is underlined and error (Cannot apply indexing with [] to an expression of type System.Data.DataRow) – mikroice90 Sep 19 '14 at 08:17
  • Ok That was my mistake i hadnt reference to System.Data and know the same problem IM002. i even write full path in dbq and nothing new – mikroice90 Sep 19 '14 at 08:32
  • 1
    Problem solved Data Source should looks like that [DataSource("System.Data.OleDB",@"Provider=Microsoft.Jet.OleDB.4.0;Data Source='|DataDirectory|'; Excel 8.0;HDR=YES","Arkusz1$",DataAccessMethod.Sequential)] – mikroice90 Sep 19 '14 at 09:10

0 Answers0