在 .NET Core 和 Visual Studio Code 中调试 xUnit 测试

编程入门 行业动态 更新时间:2024-10-22 20:26:30
本文介绍了在 .NET Core 和 Visual Studio Code 中调试 xUnit 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的是 Mac,运行 .NET Core 1.0 和 Visual Studio Code.

I'm on a Mac, running .NET Core 1.0 and Visual Studio Code.

我有一个控制台项目和一个测试项目.我已经设置了 launch.json 以便我可以调试控制台项目.

I have a console project and a test project. I have setup launch.json so that I can debug the console project.

如何设置启动配置以启动我的单元测试并附加调试器?

How do I set up a launch configuration that launches my unit tests and attaches the debugger?

推荐答案

参见 Tyler Long 的回答.在最新版本的 Visual Studio Code 中不需要以下步骤:)

See Tyler Long's answer. The steps below are not required in the newest versions of Visual Studio Code :)

我制作了一个存储库来演示.

首先,让调试器进行测试的唯一方法是添加一个文件 Program.cs,从 xUnit 控制入口点,然后手动添加代码以进行测试.这并不理想,但我想您不会经常这样做,而且很容易将其恢复正常.

First off, the only way I could get the debugger to hit the test was to add a file, Program.cs, take control of the entry point from xUnit, and manually add code to test. It's not ideal, but I imagine you aren't going to be doing this very often, and it's easy to flip it back to normal.

using System; namespace XUnitDebugging { public class Program { public static void Main(string[] args) { var test = new TestClass(); test.PassingTest(); Console.WriteLine("Enter text..."); Console.ReadLine(); } } }

接下来,在 project.json 中添加以下内容:

Next, in project.json add the following:

"buildOptions": { "emitEntryPoint": true, "debugType": "portable" },

project.json:

{ "version": "1.0.0-*", "testRunner": "xunit", "buildOptions": { "emitEntryPoint": true, "debugType": "portable" }, "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" }, "xunit": "2.2.0-beta2-build3300", "dotnet-test-xunit": "2.2.0-preview2-build1029" }, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" } } } } }

这将允许您调试 xUnit 单元测试项目.

This will allow you to debug an xUnit unit test project.

更多推荐

在 .NET Core 和 Visual Studio Code 中调试 xUnit 测试

本文发布于:2023-11-15 02:56:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1590524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   Visual   Core   NET   xUnit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!