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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:42:05+00:00 2026-05-10T17:42:05+00:00

I am writing a component that, given a ZIP file, needs to: Unzip the

  • 0

I am writing a component that, given a ZIP file, needs to:

  1. Unzip the file.
  2. Find a specific dll among the unzipped files.
  3. Load that dll through reflection and invoke a method on it.

I’d like to unit test this component.

I’m tempted to write code that deals directly with the file system:

void DoIt() {    Zip.Unzip(theZipFile, 'C:\\foo\\Unzipped');    System.IO.File myDll = File.Open('C:\\foo\\Unzipped\\SuperSecret.bar');    myDll.InvokeSomeSpecialMethod(); } 

But folks often say, ‘Don’t write unit tests that rely on the file system, database, network, etc.’

If I were to write this in a unit-test friendly way, I suppose it would look like this:

void DoIt(IZipper zipper, IFileSystem fileSystem, IDllRunner runner) {    string path = zipper.Unzip(theZipFile);    IFakeFile file = fileSystem.Open(path);    runner.Run(file); } 

Yay! Now it’s testable; I can feed in test doubles (mocks) to the DoIt method. But at what cost? I’ve now had to define 3 new interfaces just to make this testable. And what, exactly, am I testing? I’m testing that my DoIt function properly interacts with its dependencies. It doesn’t test that the zip file was unzipped properly, etc.

It doesn’t feel like I’m testing functionality anymore. It feels like I’m just testing class interactions.

My question is this: what’s the proper way to unit test something that is dependent on the file system?

edit I’m using .NET, but the concept could apply Java or native code too.

  • 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. 2026-05-10T17:42:06+00:00Added an answer on May 10, 2026 at 5:42 pm

    There’s really nothing wrong with this, it’s just a question of whether you call it a unit test or an integration test. You just have to make sure that if you do interact with the file system, there are no unintended side effects. Specifically, make sure that you clean up after youself — delete any temporary files you created — and that you don’t accidentally overwrite an existing file that happened to have the same filename as a temporary file you were using. Always use relative paths and not absolute paths.

    It would also be a good idea to chdir() into a temporary directory before running your test, and chdir() back afterwards.

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

Sidebar

Related Questions

I'm writing a component that I would like to be able to use in
I'm writing a custom file selection component. In my UI, first the user clicks
I'm writing a J2SE desktop application that requires one of its components to be
I am tasked with writing an authentication component for an open source JAVA app.
I am writing my own Joomla component (MVC), its based heavily on the newsflash
I'm writing a custom swing component (something completely new, but think JTree or JList).
I'm looking for a free winforms component for an application I'm writing. I basicly
Ideally, I only need a simple SSLSocketChannel . I already have a component that
We've been having a problem with a mass mailer component that I wrote for
I'd like to write a simple application that needs to display notes on a

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.