Visual Studio 在线:如何使用访问远程服务器的 MVC 单元测试创​​建构建定义?

Visual Studio Online: How to create a build definition with MVC Unit Testing that accesses a remote server?

我目前正在使用:

当前项目是带有 MVC 测试项目的 N 层 MVC 应用程序。该应用程序 运行 在 Azure VM(在云中)上,但可以通过作为公司域的一部分在本地访问。我创建了一些单元测试来测试控制器的动作,它们在本地通过。当我签入并使用 VSO 构建项目时,单元测试失败并出现以下错误:

Test method Enrollment.StudentEnrollment.Tests.Controllers.HomeControllerTest.SearchWithNoTermOrFilterDefaultSort threw exception: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

我假设此错误与 VSO 由于位于不同的域中而无法访问虚拟机有关,但可以使用一些帮助来解决此问题。我希望能够 运行 通过 VSO/TFS 构建我的单元测试。

我希望这里的人在这个过程中比我有更多的经验,可以帮助我将 VSO 连接到远程 server/remote SQL 服务器。

我有一些想法,但我现在不确定如何进行:

其他想法:

谢谢

您的单元测试应该能够 运行 而无需访问您的应用程序实例。否则它不是单元测试。

如果你想有趣的集成测试,那么你应该避免在构建过程中这样做。 visual studio ALM(Microsoft 测试管理器)平台中有一些工具可以处理该问题。查看实验室管理标准环境。

如果您现在真的需要这样做,那么您可以享受连接到 VSO 的自己的本地构建服务器。该本地构建服务器将在您的网络上,并且可以访问有问题的服务器。