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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:10:49+00:00 2026-05-30T03:10:49+00:00

What object types are best for writing unit tests for generic collections? Obviously if

  • 0

What object types are best for writing unit tests for generic collections? Obviously if I’m using them in a specific way in my application, it’s best to test with those types. But if I’m not, and simply creating a utility library, which types should I use?

I’m trying to avoid any pitfalls with specific object types. For example, when testing a generic dictionary structure, I know that the GetHashCode and Equals methods are very important in ensuring a valid test. I’m worried that if I simply use dummy object instances (var a = new object();), that I run into problems with these methods not being robust enough.

I’m considering using GUID instances for all of my unit testing, because of their necessarily unique constraints. However, being structs, I cannot test for equivalent references should I need to.

Lastly, are there any other gotchas to watch out for when using a specific object implementation (like object or GUID) in place of generic types for unit test purposes?

  • 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-30T03:10:50+00:00Added an answer on May 30, 2026 at 3:10 am

    If you want to be thorough, you should test with several types:

    1. A value type, such as int
    2. A reference type which uses referential equality
    3. A reference type with overridden Equals+GetHashCode
    4. Passing in an IEqualityComparer<T>
    5. double or float for their strange NaN semantics.

    Not every test needs to be done for all of them. But I’d add at least one test for each of them.

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

Sidebar

Related Questions

What is the best way to design a db with object types that share
I have a object of type ICollection<string> . What is the best way to
I'm using Oracle object data types to represent a timespan or period. And I've
I'm writing a piece of simulation software, and need an efficient way to test
What's the best ESE column type to XmlSerialize an object to my ESE DB?
I want a list of different (derived) object types working with the Default Modelbinder
I have a C# interface with certain method parameters declared as object types. However,
A strict equality operator will tell you if two object types are equal. However,
Can anyone link to or list out the object types that the iphone sdk
I have a helper assembly which includes a function to identify object types: namespace

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.