如何使用 .Net Core 和 VSCode 在调试模式下执行测试? [英] How do I do I execute tests in Debug mode using .Net Core and VSCode?

查看:29
本文介绍了如何使用 .Net Core 和 VSCode 在调试模式下执行测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 .Net Core 和 VSCode 在调试模式下执行测试?

我目前正在命令行上运行以下命令:

dotnet 测试

然而,这不是在调试模式下执行测试.

我是否附加调试器?

如果是...怎么办?

解决方案

  1. 如有必要,将测试项目转换为控制台应用程序,而不是库.例如,使用

netcoreapp2.0

  1. 添加一个主要的方法或函数.

<前>//C#课程计划{静态无效主(字符串 [] args){}}

<前>//F#模块程序 =[<入口点>]让 main(args: string[]) = 0

  1. 在 main 中,调用您要调试的测试.

  2. 在调试器中运行控制台应用程序(通常按 F5).

这应该不会影响运行 dotnet test.

How do I execute tests in Debug mode using .Net Core and VSCode?

I am currently running the following on the command line:

dotnet Test

However, this is not executing the tests in debug mode.

Do I attach a debugger?

If so... How?

解决方案

  1. If necessary, convert the test project to be a console app, instead of a library. For example, use

<TargetFramework>netcoreapp2.0</TargetFramework>

  1. Add a main method or function.

    // C#
    class Program
    {
        static void Main(string[] args)
        {
        }
    }

    // F#
    module Program =
        [<EntryPoint>]
        let main(args: string[]) = 0

  1. In the main, call the test that you want to debug.

  2. Run the console application in the debugger (usually pressing F5).

This should have no effect on running dotnet test.

这篇关于如何使用 .Net Core 和 VSCode 在调试模式下执行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆