Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7809219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:21:46+00:00 2026-06-02T03:21:46+00:00

I know that the unit test should be isolated from any dependencies. I am

  • 0

I know that the unit test should be isolated from any dependencies. I am trying to write unit tests for an application using Typemock. Issue is one of the methods in a class accepts a couple of Xml filepath parameters and then creates an XMLDocument object inside the method to be used somewhere in the method.

 public bool ValidateXml(String aFilePath, String ruleXmlPath)
 {
     XmlDocument myValidatedXml = new XmlDocument();
     try
     {
         myValidatedXml.Load(aFilePath);
     }
     catch
     {
         return false;
     }


     XmlDocument myRuleXml = new XmlDocument();
     try
     {
         myRuleXml.Load(ruleXmlPath);
     }
     catch
     {
         return false;
     }

     MyClass myObject = new MyClass(myValidatedXml);
     //Do something more with myObject.

     XmlNodeList rules = myRuleXml.SelectNodes("//rule");
     //Do something more with rules object.

     return true;
 }

How do I write a unit test for this without having to specify the physical location?
Note: I am not allowed to change the code unfortunately.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:21:48+00:00Added an answer on June 2, 2026 at 3:21 am

    You could always create a temp Xml and pass the path of the temp file and then delete it after the Test is executed. In NUnit this can be easily accomplished using [SetUp] and [TearDown] attributes.

    [TestFixture]
    public class MyTest 
    {
        private string tempPathXML;
    
        [SetUp]
        public void SetUp()
        {
            //Create XML file 
            // Save it in a temp path
        }
    
        [TearDown]
        public void TearDown()
        {
            //Delete the temp file
        }
    
        public void SampleTestForValidateXml()
        {
            //Test using tempPathXML
        }
    }
    

    the Setup method is executed before each test case and the Teardown method is executed after each test case

    Note: For MSTest the [Setup] and [TearDown] attribute can be replaced with [TestInitialize] and [TestCleanup] respectively. Thanks Cwan !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that a good unit test should never access the file system. So
I have got to know that src/test/java is used for writing unit tests. I
I have a unit test that is failing and I know why but I'm
Should I start a new project for my unit tests? That would mean that
I'm setting up a unit test in my Java EE application. I'm using JPA,
I know that in order to download a cookie associated with an account using
I'm getting started unit testing my PHP application with PHPUnit. I understand that it's
Using Visual Studio and TFS & preferably Specflow or standard unit test. I want
I read somewhere that 'minitest' is the new test::unit for ruby 1.9.2+. But ruby
I am new to unit testing and I am trying to test some of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.