如何使用 dotnet test 命令行運行單個 xunit C# 測試 (How to run a single xunit C# test using dotnet test command line)


問題描述

如何使用 dotnet test 命令行運行單個 xunit C# 測試 (How to run a single xunit C# test using dotnet test command line)

背景:我正在嘗試運行 C# 單元測試(測試使用 Xunit 框架),我的要求是運行單個單元測試,而不是整個 dll 中的所有測試

我嘗試過的事情:我嘗試了幾個命令,但到目前為止還沒有運氣.

  1. 我試過 dotnet test "complete_path/someTestDll.dll" 結果:這開始運行 dll 中的所有測試(預期但不希望)

  2. 試過dotnet test “complete_path/someTestDll.dll” \Tests:“Namespace.ClassName.MethodToRun” 結果:包含找到的測試但沒有測試匹配過濾器的 Dll。

  3. 已嘗試 dotnet test “complete_path/someTestDll.dll” ‑‑filter "FullyQualifiedName=Namespace.ClassName.MethodToRun" 沒有找到測試匹配過濾器(dll 的路徑再次正常)

  4. 試過 dotnet測試“complete_path/someTestDll.dll” ‑‑filter "DisplayName=Namespace.ClassName.MethodToRun"

不僅僅是這些,還有完整路徑、相對路徑等各種混合搭配. 等等,幾乎浪費了一整天。

注意: 我知道關於這個問題的答案很少,但我都試過了,


參考解法

方法 1:

I was able to run a single xunit test via the developer command prompt using this template.

dotnet test "complete_path/someTestDll.dll" ‑‑filter "Namespace.ClassName.MethodName"

You can also run this command to see a full list of tests available, to help double check that the paths and names in your command are correct.

dotnet test "complete_path/someTestDll.dll" ‑t

方法 2:

  1. Run inside the solution.

    dotnet test [project folder name] ‑‑filter=Namespace.ClassName.MethodName


    </li>

  2. Run inside the project.

    cd [project folder name]

    dotnet test ‑‑filter=Namespace.ClassName.MethodName


    </li>
    </ol>

    (by eRaisedToXStevJhonny Ramirez Zeballos)

    參考文件

    1. How to run a single xunit C# test using dotnet test command line (CC BY‑SA 2.5/3.0/4.0)

#command-line #xunit #.net #unit-testing #C#






相關問題

從 FFMPEG for android 的命令行版本訪問網絡攝像頭麥克風 (Accessing webcam mic from command line version of FFMPEG for android)

為什麼我的 IDE 能找到 JAR 而我的命令行卻沒有? (Why does my IDE find the JAR but my command line doesn't?)

sbt 相當於 maven exec 插件 (sbt equivalent of maven exec plugin)

無法從 Python 的命令行導入 json (Not able to import json from commandline for Python)

在命令行上使用 VS2008 部署 SharePoint 失敗 (SharePoint deployment failure using VS2008 on the comannd line)

使用 PHP 的網頁截圖? (Web Page Screenshots with PHP?)

在命令行(終端)上使用 R 腳本的最佳方式是什麼? (What's the best way to use R scripts on the command line (terminal)?)

如何創建指向 mysql 的符號鏈接?(Mac, XAMPP) (How do I create a symbolic link to mysql? (Mac, XAMPP))

如何通過終端或其他方式將參數傳遞給 JavaScriptCore/Console? (How to pass an argument to JavaScriptCore/Console via terminal, or otherwise?)

shell命令中“&&”的目的是什麼? (What is the purpose of "&&" in a shell command?)

如何使用 dotnet test 命令行運行單個 xunit C# 測試 (How to run a single xunit C# test using dotnet test command line)

在 centOS 6.9 (Final) 中將 php-5.6 升級到 7.3 時顯示多個錯誤 (Showing multiple errors while upgrading php-5.6 to 7.3 in centOS 6.9 (Final))







留言討論