简体   繁体   English

如何从 Visual Studio 中运行 XUnit 测试?

[英]How can I run XUnit tests from within Visual Studio?

I'm working on a dotnet application and am trying the XUnit testing framework for the first time.我正在开发一个 dotnet 应用程序,并且是第一次尝试 XUnit 测试框架。 I've been following the getting started tutorial .我一直在关注入门教程

I wrote my first tests and am now trying to run them.我编写了我的第一个测试,现在正在尝试运行它们。 However, the tutorial says I must open up a console an enter some obscure command但是,教程说我必须打开一个控制台并输入一些晦涩的命令

packages\xunit.runner.console.2.2.0\tools\xunit.console MyFirstUnitTests\bin\Debug\MyFirstUnitTests.dll

This seems a little painful.这似乎有点痛苦。 Why must I open up a separate command prompt to test the code?为什么我必须打开一个单独的命令提示符来测试代码? Is it possible to run the tests directly within Visual Studio?是否可以直接在 Visual Studio 中运行测试? And furthermore, this seems like an absolute mouthful to type and remember.此外,这似乎是一种绝对难以输入和记忆的内容。

The tutorial you reference is not VS-specific and is purposefully illustrating a) that you don't need an IDE and b) how to test from the commandline (some prefer this as a workflow in some cases)您引用的教程不是特定于 VS 的,而是有目的地说明 a)您不需要 IDE 和 b)如何从命令行进行测试(在某些情况下,有些人更喜欢将此作为工作流程)

See the Running tests with Visual Studio section in the getting started guide for Visual Studio请参阅 Visual Studio入门指南中的使用 Visual Studio 运行测试部分

TL;DR To get VS to pick up the tests, you need to reference the xunit.runner.visualstudio package to wire things up such that the tests get surfaced to the test discovery mechanism (this package also is the modern way in which CI configs tend to bind to test frameworks, rather than expecting you to wire up invocation of xuint.runner.console ) TL;DR 要让 VS 进行测试,您需要参考xunit.runner.visualstudio package 进行连接,以便测试出现在测试发现机制中(这个 package 也是 CI 配置的现代方式倾向于绑定到测试框架,而不是期望您连接xuint.runner.console的调用)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM