0
votes

I am trying to Include my Unit Test Cases in my Build Pipeline to run these Unit Test Cases as a part of Build. Few of my Test Cases use the Test Data stored in the XML files in the Unit Test Project. These test run successfully in my local system. But when I am trying to run these test case as a part of TFS Build pipeline, these test cases are getting failed since the Build is unable to find these XML files for data.

I tried to replace the config file App Settings for the TFS Build path but it isn't working. Still facing the same failures for the test cases. Also tried include the these files as a part of bin folder, I can see the files are present.

Below is the exception I am getting when I run the Unit Test Run as a part of TFS Build.

Assert.Fail failed. System Exception: Could not find a part of the path 'I:\Agent-Win-C_work\495\s\STARS-2.UnitTests\bin\XMLStore\CustomerRequest.xml'. Stack Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state) at System.Xml.XmlTextReaderImpl.OpenUrl() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.Load(String filename) at STARS_2.UnitTests.TestCommon.TestDataCaller.RFCXmlConnect(String fileName) in I:\Agent-Win-C_work\495\s\STARS-2.UnitTests\TestCommon\TestDataCaller.cs:line 16

Any Suggestions to resolve the issue

1
Hi Naveen, How do you reference the file in your code? Like SalamiArmy mentions you might need to use a deployment item but in any event from the stack trace it looks like the xml file is in a subfolder (XMLStore) do you refer to it with the full path or relative one? also for deployment item it would be [DeploymentItem(@"XMLStore\CustomerRequest.xml")]Etienne
Hi Naveen, any update on this ticket, did you get a chance to implement the solution that SalamiArmy suggested? Were you able to resolve?PatrickLu-MSFT
Well the suggestion provided by the SalamiArmy didn't worked in my case. We modified unit test code to load the test data using reflectionNaveen Billure

1 Answers

1
votes

Not only do you need to include those xml files your test depends on, you also need to use the [DeploymentItem(Path within the bin, path to deploy to)] to deploy them to the test agent in the build.