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

The Archive Base Latest Questions

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

Especially for C# Unit Testing , how to make a test run for various

  • 0

Especially for C# Unit Testing, how to make a test run for various inputs or an input matrix?

I very often have the case of unit tests making a matrix of inputs, but usually it can be reasonably solved by checking a list of inputs.

The simplest case is testing the addition:

  • 0 + 0 = 0
  • 1 + 0 = 1
  • 0 + -1 = -1
  • 1 + -1 = 0

The same tests would be done for each of those inputs (in this example there are 4 inputs, each associated to some expected output.

The simple solution is:

object[] inputs = ...
foreach (var input in inputs)
   // Put Assert here

The problem with that is that when you run your test it doesn’t tell for which input it failed unless you include enough details in the message log manually.

Another solution is to unroll the loop (like below). The stack trace then give which input failed and this allows to run the test for a single input again.

TestAddition(0, 0, 0);
TestAddition(1, 0, 1);
TestAddition(0, -1, -1);
TestAddition(1, -1, 0);

Last but not least, are solutions like FitNess which seem to help such cases but also add a lot of complexity and don’t seem to fit well for standard C# development.

All those solution don’t work well with fixtures, because the [TestInitialize] is called once for all inputs.

What is your solution?

Is there some feature I don’t know of that helps those cases?

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

    Its possible. The term you are missing is “Data Driven Tests” / Parameterized tests. Try with a search engine and you should find quite a few answers for your specific testing framework.

    Most of the xUnit testing frameworks have mechanisms to enable this. As Martin has posted, NUnit uses a RowTest/TestCase attribute to pass in parameters to a test.

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

Sidebar

Ask A Question

Stats

  • Questions 487k
  • Answers 488k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, Mockito does not support this. This might not be… May 16, 2026 at 8:31 am
  • Editorial Team
    Editorial Team added an answer I updated .net 4 from 4.0.2**** to 4.0.3*** that fixed… May 16, 2026 at 8:31 am
  • Editorial Team
    Editorial Team added an answer It's as simple as putting this in your Page_Load: //… May 16, 2026 at 8:31 am

Trending Tags

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

Top Members

Related Questions

No related questions found

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.