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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:15:26+00:00 2026-05-15T06:15:26+00:00

I am really starting to enjoy unit testing and have the following question to

  • 0

I am really starting to enjoy unit testing and have the following question to the gurus of unit testing.

Let’s for example say I have the following class

public class FileMapper
{
   public Dictionary<string, string> ReadFile(string filename, string delimeter){}
}

How do you guys generally go about unit testing a Parser or ReadFile method in my case?

  • 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-05-15T06:15:26+00:00Added an answer on May 15, 2026 at 6:15 am

    Given the method signature you provided, you can ‘simply’ unit test the ReadFile method by invoking it with a lot of different input and verify that the return value is correct.

    However, this can lead to Obscure Tests because very important test input is hidden away in files instead of being visible when you review each test.

    This is where TDD shows its force because it should prompt us to consider a better API.

    You could, for example, change the method to this:

    public Dictionary<string, string> ReadFile(TextReader reader, string delimeter)
    

    It’s still pretty easy to get a TextReader from a file, but now you can alternatively use a StringReader to supply unit test input.

    This change will not only make it easier to unit test the ReadFile method, but also make the method more generally usable because it no longer has a tight coupling to the file system.

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

Sidebar

Related Questions

Okay this is probably a really dumb question, however it's really starting to hurt.
I have never really done much C but am starting to play around with
I really like to have some graphic on my startup/login screen when starting my
This may be a really dumb question but I'm just starting to learn the
Ok, I'm really starting to have a bad day and the ol' brain isn't
Really starting to enjoy KnockoutJs (http://knockoutjs.com). Most of my web apps are ajax driven.
This is starting to really annoy me! I have an Excel sheet with a
I am asking this question as I am starting to really use multimethods and
This is really starting to piss me off. I feel like I have tried
I'm a complete Xcode/Objective-C/Cocoa newbie but I'm learning fast and really starting to enjoy

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.