简体   繁体   English

对.NET Core Web应用程序进行单元测试的正确方法是什么?

[英]What is the proper way to unit test .NET Core Web Application?

I'm new at web development (used to develop desktop apps). 我是Web开发的新手(用于开发桌面应用程序)。 I didn't manage to find a proper way to unit test internals of my web application. 我没有找到找到对Web应用程序内部进行单元测试的正确方法。

Let's say I do have a Foo class which do have a strictly defined behaviour (completely independed from DB and/or UI). 假设我确实有一个Foo类,它确实具有严格定义的行为(完全独立于DB和/或UI)。 I need to make sure that my implementation is corrent. 我需要确保我的实现是正确的。 In the desktop app I just add another test dll with unit tests (if the class is public) or just internal class with tests. 在桌面应用程序中,我只添加另一个带有单元测试的测试dll(如果该类是公共的)或仅带有测试的内部类。 And start it with nunit to make sure that it works. 并以nunit开头以确保其正常工作。 But how is should be done in the web application? 但是应该如何在Web应用程序中完成呢?

The only way I can think of is to add some debug-only pages on which I will run my test and ignore them during the deploy. 我唯一想到的方法是添加一些仅调试页面,我将在这些页面上运行测试,并在部署期间忽略它们。 But I think there should be some unit test framework for that and I just didn't manage to find it. 但是我认为应该为此提供一些单元测试框架,而我只是没有找到它。

Do the .net core web developers have any standard way to do it (something like nunit)? .net核心Web开发人员是否有任何标准方法(类似于nunit)?

Yes, the recommended unit testing framework to use with .NET Core apps is called Xunit. 是的,推荐与.NET Core应用程序一起使用的单元测试框架称为Xunit。 You can read an overview and walkthrough here . 您可以在此处阅读概述和演练。

暂无
暂无

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

相关问题 将ASP.Net核心Web应用程序编写的微服务部署到生产环境的正确方法是什么 - what is the proper way to deploy microservices written with ASP.Net core web application to production 单元测试 .NET 核心 3 Web API Controller - Unit test .NET Core 3 Web API Controller 如何对ASP.NET核心Web应用程序(.Net Framework)进行单元测试? - How do you unit test ASP.NET Core Web Application (.Net Framework)? 在启动显示浏览器的进程后停止/终止 .net 核心 web 应用程序进程的正确方法是什么 - What is the proper way to stop/kill a .net core web app process after launching a process to display the browser 在 .NET Core 6.0 Razor 页面应用程序中配置 Serilog 的正确方法是什么? - What's the proper way to configure Serilog in a .NET Core 6.0 Razor page application? 如何允许对.Net Core 2 Web应用程序进行参考的.Net单元测试 - How to allow .Net Unit Testing to Reference .Net core 2 web application .NET Core 应用程序中单元测试的模拟日志文件 - Mock log file for unit test in .NET Core application 有没有办法查看.NET Core中的单元测试中生成的日志消息? - Is there way to see log messages generated in a unit test in .NET Core? 在 .NET Core 3.1 中关闭 C# 套接字的正确方法是什么? - What is the proper way to close a C# Socket in .NET Core 3.1? 在C#.NET Web应用程序中每天安排任务的正确方法 - Proper way to schedule a task daily in C# .NET web application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM