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 8762843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:38:05+00:00 2026-06-13T15:38:05+00:00

I am working on a module that supplies methods for navigating directories and manipulating

  • 0

I am working on a module that supplies methods for navigating directories and manipulating files. Basically it will be a combination of the Dir and File classes, with options specific to the needs of a project I’m working on.

Right now I have started writing tests for some of these methods and things are getting messy.

Example

One of the methods I have is a tree function that returns a hash of files and folders where you can pass options like tree(only: 'folders', limit: 3). In order to test that it only goes down 3 levels, I would have to have 4+ subfolders with dummy files in them.

The Problem

Right now I’m testing on folders outside the project since the subfolders are already there, but I want to move away from this, especially considering the implausibility of testing on system files once I start testing methods equivalent to rm -rf (as well as the lack of portability).

I’m starting to think that I need to create a "lab rat" type folder that I do all my "experiments" on, but I have no clue how to approach creating it.

  • Do I create a function that creates the files?
  • Do I pull files and folders from another location?
  • Do I use some sort of "lorem ipsum" generator for file structures?
  • Do I make all these files and folders manually(ugh)?
  • Do I just mock and stub the hell out of everything and not actually create/delete the files and folders?(I don’t see this happening)

So…

How would someone normally approach testing excessive amounts of file and folder manipulation?

  • 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-13T15:38:06+00:00Added an answer on June 13, 2026 at 3:38 pm

    I don’t think you want to use mocks/stubs. The file system of your OS should be well tested and fast, so the benefit of mocks/stubs is minimal. Creating a mock/stub system increases the complexity without much benefit.

    Here’s my answers:

    Do I create a function that creates the files?

    Yes. You can create tests for these functions to make sure that they are correct. Instead of calling Dir and File, write helper functions that make the code simple and readable. Maybe you can share the helper functions between the source/test code…

    Do I pull files and folders from another location?

    Not sure what this is for…

    Do I use some sort of “lorem ipsum” generator for file structures?

    Yes, if you mean create functions that generate file structures.

    Do I make all these files and folders manually(ugh)?
    No.

    Do I just mock and stub the hell out of everything and not actually create/delete the files and folders?(I don’t see this happening)
    No. One benefit of creating files/directories is that you can manually check what is going on and not be 100% dependent on the tests. This is actually a good approach because without it there could be a bug where both the source code and test code is not doing what you expect, but you wouldn’t know because everything seems to be working.

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

Sidebar

Related Questions

I'm working on a module that, among other things, will add some generic 'finder'
I am currently working on an Apache module that uses a large mmap file
I'm working on a module that displays DWG files in WPF. I've managed to
HI, I'm working on DotNetNuke 5 module that basically consists of three pages; step
I am working on a jQuery-based plugin as a drupal module that will tweak
I have a mod_perl2 module that writes some files to the working directory. The
I'm working on a module that requires a strictly decoupled interface. Specifically, after instantiating
I am working on a module that allows users to post comments on a
I am currently working on a module that takes one of our business objects
I am currently working on a marketing module that keeps track of sites that

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.