进行集成测试时使用 web 项目 config.json
Use web project config.json when doing integration testing
我正在使用 ASP.NET 5 RC1,我需要编写集成测试...
所以在测试项目中,ASPNET5_WEB_TEST,我有以下内容:
public class IntegrationTests {
private readonly TestServer _server;
private readonly HttpClient _client;
public IntegrationTests() {
_server = new TestServer(TestServer.CreateBuilder().UseStartup<Startup>());
_client = _server.CreateClient();
}
// Test methods ...
}
Startup class 来自我正在测试的 ASP.NET 5 项目:ASPNET5_WEB
当我 运行 测试时出现以下错误:
The configuration file 'C:\Projects\ASPNET5_TEST\config.json' was not found and is not optional.
我知道我收到此错误是因为在启动时我有:
builder
.AddJsonFile("config.json", false)
.AddJsonFile($"config.{environment.EnvironmentName}.json", true);
要修复此错误,我至少需要将 config.json 从我的 Web 项目 ASPNET5_WEB 复制到我的测试项目 ASPNET5_WEB_TEST。但这意味着我将需要维护副本 config.json 或至少在每次进行更改时复制它。
我不能告诉 TestServer 使用 Web 项目的 Startup 及其 config.*.json 文件吗?
我可以有一个 config.testing.json 并在 TestServer 上将环境设置为测试,以便启动代码使用 config.json 和 config.testing.json 吗?
我假设您使用的是 aspnet
中的 TestServer
,如果是这样,那么它并不是为支持您读取配置文件的方式而构建的。 TestServer
用于 运行 简单 对其 "hosting engine" 的集成测试,但不适用于网站的集成测试。
他们的 ApplicationDeployerFactory class is what you can use however. Refer to this 作为如何 运行 一个 "integration" 服务器的例子。我已经将 selenium 与它结合使用 运行 针对我正在处理的 atm 项目进行集成测试。
是的,你可以。
看看这个问题 https://github.com/aspnet/Mvc/issues/3410 和提到的包。
基本上你需要实现自己的IApplicationEnvironment
我正在使用 ASP.NET 5 RC1,我需要编写集成测试...
所以在测试项目中,ASPNET5_WEB_TEST,我有以下内容:
public class IntegrationTests {
private readonly TestServer _server;
private readonly HttpClient _client;
public IntegrationTests() {
_server = new TestServer(TestServer.CreateBuilder().UseStartup<Startup>());
_client = _server.CreateClient();
}
// Test methods ...
}
Startup class 来自我正在测试的 ASP.NET 5 项目:ASPNET5_WEB
当我 运行 测试时出现以下错误:
The configuration file 'C:\Projects\ASPNET5_TEST\config.json' was not found and is not optional.
我知道我收到此错误是因为在启动时我有:
builder
.AddJsonFile("config.json", false)
.AddJsonFile($"config.{environment.EnvironmentName}.json", true);
要修复此错误,我至少需要将 config.json 从我的 Web 项目 ASPNET5_WEB 复制到我的测试项目 ASPNET5_WEB_TEST。但这意味着我将需要维护副本 config.json 或至少在每次进行更改时复制它。
我不能告诉 TestServer 使用 Web 项目的 Startup 及其 config.*.json 文件吗?
我可以有一个 config.testing.json 并在 TestServer 上将环境设置为测试,以便启动代码使用 config.json 和 config.testing.json 吗?
我假设您使用的是 aspnet
中的 TestServer
,如果是这样,那么它并不是为支持您读取配置文件的方式而构建的。 TestServer
用于 运行 简单 对其 "hosting engine" 的集成测试,但不适用于网站的集成测试。
他们的 ApplicationDeployerFactory class is what you can use however. Refer to this 作为如何 运行 一个 "integration" 服务器的例子。我已经将 selenium 与它结合使用 运行 针对我正在处理的 atm 项目进行集成测试。
是的,你可以。
看看这个问题 https://github.com/aspnet/Mvc/issues/3410 和提到的包。
基本上你需要实现自己的IApplicationEnvironment