.NET Core 單元測試
使用的PowerShell命令
1.建立專案相關命令
ls
mkdir
ni (new-item) 建立空檔案
add-content 向檔案新增內容
type 開啟檔案
dotnet new sln 建立空解決方案
dotnet sln add *.csproj 向解決方案新增專案
dotnet new classlib 建立程式集
dotnet new mstest (建立MSTest專案)
dotnet add reference *.csproj (當前程式集新增其他程式及引用)
2.執行測試相關命令
dotnet test 執行所有
測試
dotnet test --filter Method (執行完整名字包含Method 的測試方法)
dotnet test --filter Name~TestMethod1 (執行名稱中包含TestMethod1的方法)
dotnet test --filter ClassName=MSTestNamespace.UnitTest1 (執行MSTestNamespace.UnitTest1類中的測試)
dotnet test --filter FullyQualifiedName!=MSTestNamespace.UnitTest1.TestMethod1 (執行MSTestNamespace.UnitTest1.TestMethod1之外所有測試)
dotnet test --filter TestCategory=CategoryA (執行含 [TestCategory("CategoryA")]
批註的測試。)
dotnet test --filter Priority=2 (執行含 [Priority(2)]
批註的測試。)
dotnet vstest <MyPublishedTests>.dll 對釋出過的測試專案執行測試 (如果你的應用以 netcoreapp
之外的框架為目標,則仍然可以通過使用框架標誌傳入目標框架來執行 dotnet vstest