简体   繁体   English

SQL数据表作为单元测试中的测试数据

[英]SQL data table as test data in Unit Tests

I have tried unit testing with test data from excel sheet and it worked fine (after following the instructions from MSDN dosuments). 我已经尝试使用excel表格中的测试数据进行单元测试,并且效果很好(遵循了MSDN文档的说明)。 However now I would like to take the test data directly from data base, can anyone please tell me the steps to follow as I was unable to find related document in the Website. 但是,现在我想直接从数据库中获取测试数据,由于我无法在网站上找到相关文档,因此任何人都可以告诉我要执行的步骤。

I am using Microsoft Visual Studio 2012 and Microsoft SQL Server Management Studio. 我正在使用Microsoft Visual Studio 2012和Microsoft SQL Server Management Studio。 Is there anything else also I need in order to acheive the task? 我还需要其他什么来完成任务吗?

Regards, 问候,

SJ SJ

I am using Microsoft Unit Test Framework. 我正在使用Microsoft单元测试框架。 In this we can add a data source for unit testing. 在此,我们可以添加用于单元测试的数据源。 I added the following data source for Excel sheet: 我为Excel工作表添加了以下数据源:

 <connectionStrings>
    <add name="MyExcelConn"
         connectionString="Dsn=Excel Files;dbq=.\\CoreTestData.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5"
         providerName="System.Data.Odbc" />
  </connectionStrings>

  <microsoft.visualstudio.testtools>
    <dataSources>
      <add name="MyExcelDataSource"
           connectionString="MyExcelConn"
           dataTableName="Sheet1$"
           dataAccessMethod="Sequential"/>
   </dataSources>
  </microsoft.visualstudio.testtools>

Now wondering if we can somehow do the same with data table. 现在想知道我们是否可以对数据表执行相同的操作。 Reference : http://msdn.microsoft.com/en-us/library/ms182527.aspx 参考: http : //msdn.microsoft.com/zh-cn/library/ms182527.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取通用单元测试的通用测试数据 - Getting generic test data for generic unit tests 所有单元测试仅准备一次集成测试测试数据 - Prepare Integration Test test data only once for ALL Unit Tests Microsoft单元测试-在测试配置设置中找不到数据源 - Microsoft Unit Tests - Data source cannot be found in the test configuration settings 避免为单元测试重复测试数据的正确方法 - Proper way to avoid duplicating test data for unit tests 定时器触发单元测试 Azure Function:提供测试数据 - Unit Tests for timer triggered Azure Function: provide test data 是否可以在C#单元测试中测试SQL数据? - Is it possible to test SQL data in a C# unit test? 数据驱动单元测试问题 - Data driven unit tests problem 当新测试项目的测试被引入解决方案时,MSTest单元测试适配器无法连接到数据源 - MSTest Unit Test Adapter Failing to Connect to Data Source When Tests From New Test Project Are Introduced to Solution 针对 SQL 服务器数据运行 XUnit 测试时出错 - 为 Tests.UnitTest1.Test1 上的 Tests.SqlServerDataAttribute 指定的数据发现器不存在 - Error running XUnit Test against SQL Server Data - Data discoverer specified for Tests.SqlServerDataAttribute on Tests.UnitTest1.Test1 does not exist 在集成测试中添加测试数据 - Add test data in integration tests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM