Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

mocking a resource like a directory in unit testing

Question posted by: andho (Member) on May 25th, 2008 08:58 AM
I need to mock a resource like a directory in one of my unit tests.
The method is checking if the directory exists and i don't want to create a directory just for testing purposes so is there anyway to mock the resource without actually creating it or is it a good idea to create the directory when setting up the fixture?
RedSon's Avatar
RedSon
Site Moderator
2,917 Posts
May 29th, 2008
03:52 PM
#2

Re: mocking a resource like a directory in unit testing
Quote:
I need to mock a resource like a directory in one of my unit tests.
The method is checking if the directory exists and i don't want to create a directory just for testing purposes so is there anyway to mock the resource without actually creating it or is it a good idea to create the directory when setting up the fixture?


In your test fixture create the directory then run the test then delete the directory. You should be able to use known good directory creation APIs to make the file then use those same APIs to delete the file after you are done with it.

Reply
andho's Avatar
andho
Member
34 Posts
May 30th, 2008
08:59 AM
#3

Re: mocking a resource like a directory in unit testing
thanks that works fine.

But would that create any adverse effect if im testing it in a checked out repository (from SVN, CVS or sort) and then commiting the changes later?

Well anyway i just wanted to know if it was a good idea so thanks :)

Reply
RedSon's Avatar
RedSon
Site Moderator
2,917 Posts
May 30th, 2008
02:56 PM
#4

Re: mocking a resource like a directory in unit testing
Quote:
thanks that works fine.

But would that create any adverse effect if im testing it in a checked out repository (from SVN, CVS or sort) and then commiting the changes later?

Well anyway i just wanted to know if it was a good idea so thanks :)

No SVN/CVS has no knowledge of directories in your working repository unless you add it.

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,846 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Software Development Forum Contributors