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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 171k
  • Answers 171k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes and no. The one way is to simply override… May 12, 2026 at 2:13 pm
  • Editorial Team
    Editorial Team added an answer If you're option-clicking I believe only symbols in the frameworks… May 12, 2026 at 2:13 pm
  • Editorial Team
    Editorial Team added an answer (2.) can I configure credentials as command line arguments to… May 12, 2026 at 2:13 pm

Related Questions

Can anyone help, i trying to figure what i need to do, i have
Some of my recent web projects that I worked on, use a flow engine
I am writing a number of small, simple applications which share a common structure
I am attempting to develop a service that contains numerous client and server sockets

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.