Quantcast
Viewing all articles
Browse latest Browse all 428

【茶包射手筆記】NUnit 發生 OutOfMemoryException

從 Github 取得 ServiceStack.Text想幫忙修 Bug。專案使用 NUnit 跑單元測試,為方便測試,在 Visual Studio 2017 安裝 NUnit 3 Test Adapter,安裝後可由 Test Explorer 直接執行測試。

Image may be NSFW.
Clik here to view.

不料,編譯後 Test Explorer 只找到一項測試,Output / Tests 則出現大量 OutOfMemoryException:

Image may be NSFW.
Clik here to view.

Exception System.OutOfMemoryException, Exception converting ServiceStack.Text.Tests.XmlSerializerTests.serialize_Territory
已發生類型 'System.OutOfMemoryException' 的例外狀況。

爬文找到解法,原因出在 NUnit 還不支援 .NET Core 使用的新版 Portable PDB 格式(未來的新標準),而 ServiceStack.Text.Tests 是一個 .NET Core 專案(同時支援 net45 與 netcoreapp1.0),.NET Core 版本的 PDB 導致問題。解決方法是在 csproj 中加入以下 PropertyGroup,指定當 Target 不等於 netcoreapp1.0 時 DebugType = Full 以產生 Windows 版 PDB:(預設 DebugType 為 Portable,Full 應源自 Full Framework,不是指完整版 PDB,參考

  <PropertyGroup>
    <DebugType Condition="'$(TargetFramework)' != '' AND '$(TargetFramework)' != 'netcoreapp1.0'">Full</DebugType>
  </PropertyGroup>

Image may be NSFW.
Clik here to view.

加入設定後,Test Explorer 順利找到測試項目並成功跑完,綠燈!

Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 428

Trending Articles