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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:37:47+00:00 2026-05-26T12:37:47+00:00

I have a situation where I need to unit test some scenarios that require

  • 0

I have a situation where I need to unit test some scenarios that require some pre-initialization of very large collections, but the pre-initialized data needs to be hard-coded for the unit tests to work.

Are there typical practices for this kind of thing? Or do most of you just make a clunky variable inside of each unit test and use that? I’ve been very curious about how other developers are tackling this situation..

  • 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-26T12:37:48+00:00Added an answer on May 26, 2026 at 12:37 pm

    If this data is sort of used in lots of different tests, then we use a static container to hold the data (assuming the data doesn’t change). Tests can then just reference this when needed.

    If the data is specific to a fixture, then it’s just made a part of the fixture in order to keep the scope narrow.

    For other parts of data, we can use mocking / stubbing techniques to expose test data. A lot of our data comes through our DAL interfaces, even the static stuff, so for that we have stubbed a test implementation of the interface that provides the static data through the normal interface methods we use. Lots of our tests are built on using this stub.

    We use this in conjunction with SpecFlow. We can define Background: tables that are fed into the DAL stub, this DAL is then injected when our code under test is using the DAL interfaces to talk to data. For large amounts of static data, we simply hard-code it or code-gen it into an area where the DAL stub can get it on request.

    Of course, this isn’t necessarily how you should do it. This is just how I’ve seen it handled.


    but the pre-initialized data needs to be hard-coded for the unit tests
    to work

    In my opinion, there is nothing wrong with tests requiring set data in order to prove output. We have a mix of true unit tests, where external things are separated and we test just a method in question, but then with SpecFlow we have sort of “use case” tests, where we test things in a broader scope. However, this still needs defined input.


    One important thing to keep under control is that unit tests should be as separated as possible. Fixtures allow you to expand the scope to a small collection of tests, but if you find yourself with lots of backing data that is potentially mutable being used across lots of tests – you need to take a step back.

    We recently had this with a static list of configuration actions that weren’t immutable. Making a change affected tests run after the change. We identified this and rectified it, but it wasn’t trivial.

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

Sidebar

Related Questions

I have a situation where I need to write some unit tests for some
I have a situation where I need to notify some users when something in
I need to create a unit test for a method that returns an xmldocument.
I have a situation where I need to create some kind of uniqueness between
I have situation where I need to change the order of the columns/adding new
I have a situation where I need to be able to load assemblies in
I have a situation where I need to work with a datagrid and adding
I have a situation where i need to debug a Windows CE application in
I have a situation where I need to add an arbitrary unique id to
I have a situation where I need to do something like select 2, id

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.