admin管理员组文章数量:1418346
I might be being silly but can I use aspire like test containers > aka I want to spin up a container and run tests on it?
I have tried to use MS docs but it wants you to reference a c# project that I don't have.
I might be being silly but can I use aspire like test containers > aka I want to spin up a container and run tests on it?
I have tried to use MS docs but it wants you to reference a c# project that I don't have.
Share Improve this question asked Jan 29 at 16:54 TPLTPL 454 bronze badges1 Answer
Reset to default 3Yes. But it has extra steps. You have probably already found these links or similar ones:
https://learn.microsoft/en-us/dotnet/aspire/app-host/withdockerfile
https://learn.microsoft/en-us/dotnet/aspire/testing/write-your-first-test?pivots=xunit
Create an Aspire host project with the template setup
Add whatever containers you want to the app setup in the Host project
Create a test project
Reference Aspire.Hosting.Testing and the host project you just made in your test project
In the test project load the host project with the special command
var appHost = await DistributedApplicationTestingBuilder .CreateAsync<Projects.{NAME OF YOUR HOST PROJECT WITH UNDERSCORES}>();
The project reference will dynamically add the Host project name to the
Projects
classBuild the appHost
Get the resourceNotificationService for the resource/container you want to connect to
Start the AppHost
Wait for the resource to be ready via the notfication service
Use the resourceNotificationService to get the ports that the container/resource is exposed on. these will be random ports. The Aspire Dashboard doesn't load, so you don't get the port you configured in the Host project
Connect to the container and run your test.
本文标签: Unit testing with aspire with containersStack Overflow
版权声明:本文标题:Unit testing with aspire with containers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745288649a2651656.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论