问题描述
我很喜欢 Visual Studio Online 中的新构建工具.允许我做我在本地构建服务器上所做的几乎所有事情.但我缺少的一件事是集成数据库测试:对于每次构建运行,我从脚本重新创建测试数据库并针对它运行 DB 测试.
I'm enjoying the new Build tool in Visual Studio Online. Allows me to do almost everything that I do my local build server. But one thing that I'm missing is integration database tests: for every build run I re-create test database from scripts and run DB-tests against it.
在 Visual Studio Online 中,我似乎找不到任何可满足我需要的数据库实例.
In Visual Studio Online I can't seem to find any database instance available for my needs.
我尝试为每次构建运行创建 Azure SQL 数据库(通过 PowerShell),然后在构建完成后将其删除.但是创建数据库需要很长时间(与构建过程的其余部分相比).即使完成了 PowerShell 脚本,数据库还没有准备好接受请求 - 我需要不断检查它是否真的准备好了.所以这个场景变得过于复杂且不可靠.
I have tried creating Azure SQL database (via PowerShell) for every build run and then delete it after the build is complete. But it takes forever (comparing to the rest of the build process) to create a database. And even when PowerShell scripts are done, database is not yet ready to accept requests - I need to constantly check if it is actually ready. So this scenario becomes too complex and not reliable.
是否还有其他选项可以在 Visual Studio Online 中进行数据库 (SQL Server) 集成测试?
Are there other options to do database (SQL Server) integration tests in Visual Studio Online?
更新:我想我不太清楚我需要什么 - 我需要一个免费(非常便宜)的 SQL Server 实例来连接到在 VSO 中的构建代理上运行的实例.像 SQL Express 或 SQL CE 或 LocalDB 之类的东西,我可以在其中连接并重新创建数据库以运行 C# 测试.重新创建数据库或运行测试不是问题,有一个有效的连接字符串是一个问题.
Update: I think I'm not very clear of what I need - I need a free (very cheap) SQL Server instance to connect to that runs on build agent in VSO. Something like SQL Express or SQL CE or LocalDB, where I can connect to and re-create database to run C# tests against. Re-creating database or running tests is not a problem, having a valid connection string is a problem.
2016 年 10 月更新: 我已经在博客中介绍了我如何在 VSTS 中进行集成测试
Update Oct 2016: I've blogged about how I do integration testing in VSTS
推荐答案
TFS 构建服务器预装了 MSSQL Server 2012 和 MSSQL Server 2014 LocalDB.
The TFS build servers come with MSSQL Server 2012 and MSSQL Server 2014 LocalDBs preinstalled.
来源: TFS 服务 - 托管构建服务器上的软件
因此,只需将以下单行代码放入解决方案的构建后事件中,即可根据您的需要创建 MYTESTDB LocalDB 实例.这将允许您连接到 (LocalDB)MYTESTDB
并运行数据库集成测试就好了.
So, just put the following one-liner into your solution's post-build event to create a MYTESTDB LocalDB instance for your needs. This will allow you to connect to (LocalDB)MYTESTDB
an run the database integration tests just fine.
"C:Program FilesMicrosoft SQL Server120ToolsBinnSqlLocalDB.exe" create "MYTESTDB" 12.0 -s
来源: SqlLocalDB 实用工具
这篇关于Visual Studio Online 中的数据库集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!