[英]System.Xml.XmlException occurs with dotnet test
使用.NET Core的單元測試功能以及MSTest框架和適配器,我試圖運行此簡單的單元測試:
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TESTFull
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Assert.AreEqual(1, 2);
}
}
}
然而,即使有了腳手架的依賴關系:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.11" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.11" />
</ItemGroup>
</Project>
使用dotnet test
命令時出現以下錯誤:
Test run for F:\Onedrive\Uni\2-1\Dev Project 1 - Tools & Practices\RESTFull\TESTFull\bin\Debug\netcoreapp1.1\TESTFull.dll(.NETCoreApp,Version=v1.1)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Unhandled Exception: System.Xml.XmlException: An error occurred while parsing EntityName. Line 1, position 44.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, Int32 lineNo, Int32 linePos)
at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos)
at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
at System.Xml.XmlTextReaderImpl.FinishPartialValue()
at System.Xml.XmlTextReaderImpl.get_Value()
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.ParsePartialContent(XmlNode parentNode, String innerxmltext, XmlNodeType nt)
at System.Xml.XmlLoader.LoadInnerXmlElement(XmlElement node, String innerxmltext)
at System.Xml.XmlElement.set_InnerXml(String value)
at Microsoft.VisualStudio.TestPlatform.Utilities.XmlUtilities.AppendOrModifyChild(XPathNavigator parentNavigator, String nodeXPath, String nodeName, String innerXml)
at Microsoft.VisualStudio.TestPlatform.Utilities.InferRunSettingsHelper.UpdateRunConfiguration(XPathNavigator navigator, Architecture effectivePlatform, Framework effectiveFramework, String resultsDirectory)
at Microsoft.VisualStudio.TestPlatform.Utilities.InferRunSettingsHelper.UpdateRunSettingsWithUserProvidedSwitches(XPathNavigator runSettingsNavigator, Architecture architecture, Framework framework, String resultsDirectory)
at Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities.RunSettingsUtilities.GetEffectiveRunSettings(String runSettings, CommandLineOptions commandLineOptions)
at Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities.RunSettingsUtilities.GetRunSettings(IRunSettingsProvider runSettingsProvider, CommandLineOptions commandlineOptions)
at Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.RunTestsArgumentExecutor.RunTests(IEnumerable`1 sources)
at Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.RunTestsArgumentExecutor.Execute()
at Microsoft.VisualStudio.TestPlatform.CommandLine.Executor.ExecuteArgumentProcessor(IArgumentProcessor processor, Int32& exitCode)
at Microsoft.VisualStudio.TestPlatform.CommandLine.Executor.Execute(String[] args)
at Microsoft.VisualStudio.TestPlatform.CommandLine.Program.Main(String[] args)
請注意,使用空的TestMethod1()
以及使用內置的xUnit項目模板時,也會發生此錯誤。 我正在使用.NET Core 1.1。
或者使用我不能重現這個問題MSTest
還是XUnit
。 存在可能區域看將是Versions
的PackageReference
尤其是MSTest
和XUnit
。 在Nuget
查找您的版本,並驗證其支持的.net標准版本。
問題是您的文件路徑。 目前, dotnet test
無法處理其中包含與號(即&
字符)的文件路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.