如何测试在Visual Studio容器工具中运行的应用程序
如何使用Visual Studio Container Tools
在App dockerized上运行TestExplorer的测试?
我具有带有多个WebAPI应用程序的ASPNET解决方案:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () =>
{
return "Hello world";
});
app.Run();
我想测试我的服务:
public class UnitTest1
{
private HttpClient _client;
public UnitTest1()
{
_client = new HttpClient();
}
[Fact]
public async Task Test1Async()
{
await _client.GetAsync("http://webapi1");
}
[Fact]
public async Task Test2Async()
{
await _client.GetAsync("http://webapi2");
}
}
我有以下docker组成:
services:
webapi1:
image: ${DOCKER_REGISTRY-}webapi1
build:
context: .
dockerfile: webapi1/Dockerfile
webapi2:
image: ${DOCKER_REGISTRY-}webapi2
build:
context: .
dockerfile: webapi2/Dockerfile
tests:
image: ${DOCKER_REGISTRY-}tests
build:
context: .
dockerfile: tests/Dockerfile
在此设置中,我可以登录测试容器并运行dotnet Test
运行测试。但是,似乎没有办法使用测试资源管理器或调试测试。
How can I run tests from TestExplorer on app dockerized using Visual Studio Container Tools
?
I have aspnet solution with multiple webapi apps:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () =>
{
return "Hello world";
});
app.Run();
I would like to test my services:
public class UnitTest1
{
private HttpClient _client;
public UnitTest1()
{
_client = new HttpClient();
}
[Fact]
public async Task Test1Async()
{
await _client.GetAsync("http://webapi1");
}
[Fact]
public async Task Test2Async()
{
await _client.GetAsync("http://webapi2");
}
}
I have following docker compose:
services:
webapi1:
image: ${DOCKER_REGISTRY-}webapi1
build:
context: .
dockerfile: webapi1/Dockerfile
webapi2:
image: ${DOCKER_REGISTRY-}webapi2
build:
context: .
dockerfile: webapi2/Dockerfile
tests:
image: ${DOCKER_REGISTRY-}tests
build:
context: .
dockerfile: tests/Dockerfile
In this setup I can login onto my test container and run dotnet test
to run tests. However there seems to be no way to run tests using test explorer, or debug them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论