简体   繁体   English

针对 ASP.NET REST Web ZDB974238714CA8DE63FZACE7服务器运行单元测试的最佳方法是什么

[英]What's the best way to run unit tests against an ASP.NET REST Web API server

We have an ASP.NET Web API server app that provides a REST API. We have an ASP.NET Web API server app that provides a REST API.

What I want is pretty simple.我想要的很简单。 That when our unit tests run, and I prefer NUnit but can do the Microsoft test framework, that it would fire up the server app.当我们的单元测试运行时,我更喜欢 NUnit 但可以执行 Microsoft 测试框架,它会启动服务器应用程序。 And I then have unit tests written that make REST calls and assert the returned response.然后我编写了单元测试,使 REST 调用并断言返回的响应。

Which leaves the questions:这留下了问题:

  1. Is there a way when the tests start, to first get our server web app up and running on IIS Express.有没有办法在测试开始时,首先让我们的服务器 web 应用程序在 IIS Express 上运行。 And not start the tests until it is running and available.并且在它运行并可用之前不要开始测试。
  2. Is there a way to either hard-code the port for the web app on IIS Express or to get the port for the unit tests?有没有办法在 IIS Express 上硬编码 web 应用程序的端口或获取单元测试的端口?
  3. How do I get IIS Express to end my web app and then exit?如何让 IIS Express 结束我的 web 应用程序然后退出?
  4. To do this, do I then need all the tests in one suite so I'm not starting & stopping multiple instances of our web app?为此,我是否需要在一个套件中进行所有测试,这样我就不会启动和停止 web 应用程序的多个实例?

You described a integration tests in asp.net core and there is quite good documentation for that starting with this您在 asp.net 内核中描述了一个集成测试,并且从这个开始有相当好的文档

You need to basically setup a host inside your IntegrationTests solution using Generic host and then all points 1-4 are covered您基本上需要使用通用主机在您的 IntegrationTests 解决方案中设置一个主机,然后涵盖所有点 1-4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在ASP.NET Web API中存储(不记录)REST错误消息的最佳方法 - best way for storing (not logging) REST error messages in ASP.NET Web API 在Asp.net Web API项目中用于演示的最佳数据存储方式是什么 - What is the best way to use in memory data in Asp.net Web API project for demo 如何更改ASP.NET调用REST Web API的方式 - How to change the way REST Web API is called for ASP.NET 在ASP.Net中处理web.config文件版本的最佳方法是什么? - What's the best way to handle web.config file versions in ASP.Net? 处理asp.net Web Api中未经身份验证的请求的最佳方法 - Best way to handle unauthenticated request in asp.net Web Api 为了获得基本的代码覆盖率,我应该针对ASP.NET MVC控制器运行哪些测试? - To achieve basic code coverage what tests should I run against an ASP.NET MVC Controller? ASP.NET Web API最佳实践,将数据发送到服务器 - ASP.NET Web API best practice to send data to the server 在 ASP.NET 上检测 JSON 请求的最佳方法是什么 - What's the best way to detect a JSON request on ASP.NET 在ASP.NET中检查用户浏览器的最佳方法是什么? - What is the best way to check the user's browser in ASP.NET? 在ASP.NET中显示缩略图的最佳方法是什么? - What's the best way of displaying thumbnails in ASP.NET?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM