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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:41:12+00:00 2026-05-31T18:41:12+00:00

I have a unit test like so: [Test] public void DataIn_NoOfRowsReached_CreatesSequentialData() { //Assert MyLogic

  • 0

I have a unit test like so:

    [Test]
    public void DataIn_NoOfRowsReached_CreatesSequentialData()
    {
        //Assert
        MyLogic logic = SetupLogic();
        logic.NoOfRows = 3;

        logic.DataIn(1, "1,4,7");
        logic.DataIn(2, "2,5,8");
        logic.DataIn(3, "3,6,9");

        CollectionAssert.AreEqual(new[] { "1", "2", "3", "4", "5", "6", "7", "8", "9" }, logic.ExpectedValues);
    }

Each DataIn call adds the passed in data to a separate list depending on ID (1st param). When the NoOfRows number equals the DataIn input Id it merges the data to be sequential. I then test to check this.

I now want to use test cases but I cannot see any easy way to do this without putting if statements and various optional parameters in the test method. I don’t really want to duplicate the tests for various scenarios.

The NoOfRows maximum is 6.

  • 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-31T18:41:13+00:00Added an answer on May 31, 2026 at 6:41 pm

    I believe this is what you are looking for. Leverage the params keyword to allow passing in an arbitrary amount of strings.

    [Test]
    public void DataIn_NoOfRowsReached_CreatesSequentialData()
    {
        MyGenericTest("1,4,7", "2,5,8", "3,6,9");
    }
    
    private void MyGenericTest(params string[] inputs)
    {
        //Assert
        MyLogic logic = SetupLogic();
        logic.NoOfRows = inputs.Length;
    
        List<string> allNumbers = new List<string>();
        for(int i = 0; i < inputs.Length; i++)
        {
           logic.DataIn(i + 1, inputs[i]);
           allNumbers.AddRange(inputs[i].Split(',');
        }
    
        allNumbers.Sort();
        CollectionAssert.AreEqual(allNumbers.Distinct(), logic.ExpectedValues);
    }
    

    This just does string sorting… if you have numbers that are bigger than 9, you’ll want to add your own compare function to the Sort() method.

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

Sidebar

Related Questions

I have a unit-test that tests a variety of cases, like this: public void
I have the following unit test: [TestMethod] public void Add_Returns_Edit_View() { // Act ActionResult
Ought I to unit test constructors? Say I have a constructor like this: IMapinfoWrapper
Is there any good way to unit test destructors? Like say I have a
I have a method like public abstract class Base { public void MethodUnderTest(); }
Suppose I have a function like this: public void AddEntry(Entry entry) { if (entry.Size
What ways do I have for creating a unit test template like this? I'm
So say I'm doing TDD and I write a test like this: public void
I have a bunch of methods returning HashSet. I would like my unit test
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and

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.