By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,529 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,529 IT Pros & Developers. It's quick & easy.

mocking a resource like a directory in unit testing

P: 34
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?
May 25 '08 #1
Share this Question
Share on Google+
3 Replies


RedSon
Expert 5K+
P: 5,000
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.
May 29 '08 #2

P: 34
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 :)
May 30 '08 #3

RedSon
Expert 5K+
P: 5,000
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.
May 30 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.