none
DataSource attribute for unit test method RRS feed

  • Question

  • I try to use CSV data source in Device unit test (WinCE/Pocket PC2003 Emulator)

    I have added source in using wizard in Data Connection String property:
    using Microsoft.VisualStudio.TestTools.UnitTesting;    ....    
    
    [TestMethod()]
    [DeploymentItem("Options.txt")]
    [DeploymentItem("Options_1.txt")]
    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "C:\\...\\Tests\\Data\\LoadSettingsTest.csv", "LoadSettingsTest#csv", DataAccessMethod.Sequential)]
    public void LoadSettingsTest()    
    {      
    ...    
    }



    I have following compiler error:

    > Error    1 The type or namespace name 'DataSource' could not be found
    > (are you missing a using directive or an assembly reference?)
    >
    > Error    2 The type or namespace name 'DataSourceAttribute' could not be
    > found (are you missing a using directive or an assembly reference?)

    What's? Where DataSource is defined? Is data DataSource attribute supported in device unit tests?
    Wednesday, March 5, 2014 9:45 AM

Answers

  • Hi hellboy_1981,

    Welcome to MSDN Forum.

    The DataSourceAttribute class provides two ways to specify data source information for data-driven tests.  The first way specifies information through a connection string, provider information, and source table name passed to the DataSource attribute.

    Connection String Example:

    [DataSource("Provider=SQLOLEDB.1;Data Source=MySource;Integrated] Security=SSPI;Initial Catalog=MyCatalog;Persist Security Info=False", "MyTable")]

    The second way passes a single argument to the attribute that specifies the configuration setting located in the app.config file.

    Configuration Setting Example:

    [DataSource("dataSourceNameFromConfigFile")]

    More information:

    #How To: Create a Data-Driven Unit Test

    http://msdn.microsoft.com/en-us/library/ms182527.aspx#bkmk_specifying_the_datasourceattribute

    Hope this helps you.

    Best Regards,

    Eileen


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, March 6, 2014 8:08 AM
    Moderator

All replies

  • Hi hellboy_1981,

    Welcome to MSDN Forum.

    The DataSourceAttribute class provides two ways to specify data source information for data-driven tests.  The first way specifies information through a connection string, provider information, and source table name passed to the DataSource attribute.

    Connection String Example:

    [DataSource("Provider=SQLOLEDB.1;Data Source=MySource;Integrated] Security=SSPI;Initial Catalog=MyCatalog;Persist Security Info=False", "MyTable")]

    The second way passes a single argument to the attribute that specifies the configuration setting located in the app.config file.

    Configuration Setting Example:

    [DataSource("dataSourceNameFromConfigFile")]

    More information:

    #How To: Create a Data-Driven Unit Test

    http://msdn.microsoft.com/en-us/library/ms182527.aspx#bkmk_specifying_the_datasourceattribute

    Hope this helps you.

    Best Regards,

    Eileen


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, March 6, 2014 8:08 AM
    Moderator
  • I'm afraid, no. The Smart Device Unit Testing Framework (that runs on WinCE) does not Support data-driven unit test.

    This is documented in MSDN under: http://msdn.microsoft.com/en-us/library/bb545998(v=vs.90).aspx


    MVP Windows Embedded

    Friday, March 21, 2014 1:24 PM
    Moderator