問題描述
如何使用 dotnet test 命令行運行單個 xunit C# 測試 (How to run a single xunit C# test using dotnet test command line)
背景:我正在嘗試運行 C# 單元測試(測試使用 Xunit 框架),我的要求是運行單個單元測試,而不是整個 dll 中的所有測試。
我嘗試過的事情:我嘗試了幾個命令,但到目前為止還沒有運氣.
我試過
dotnet test "complete_path/someTestDll.dll"
結果:這開始運行 dll 中的所有測試(預期但不希望)試過
dotnet test “complete_path/someTestDll.dll” \Tests:“Namespace.ClassName.MethodToRun”
結果:包含找到的測試但沒有測試匹配過濾器的 Dll。已嘗試
dotnet test “complete_path/someTestDll.dll” ‑‑filter "FullyQualifiedName=Namespace.ClassName.MethodToRun"
沒有找到測試匹配過濾器(dll 的路徑再次正常)試過
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:
Run inside the solution.
dotnet test [project folder name] ‑‑filter=Namespace.ClassName.MethodName
</li>Run inside the project.
cd [project folder name]
dotnet test ‑‑filter=Namespace.ClassName.MethodName
</li>
</ol>(by eRaisedToX、Stev、Jhonny Ramirez Zeballos)
參考文件