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

The Archive Base Latest Questions

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

I have 1 unit test method that needs several parameters. I would like to

  • 0

I have 1 unit test method that needs several parameters. I would like to run this test once for every possible value of a cartesian with a predefined list for each parameter. I imagine that parameters could be passes in via the test context, but I do not want to connect to an external database.

For example: If I had 2 parameters with the following possible values, the test would execute 6 times (order doesn’t matter). (pseudo-code)

p1 = { 1, 5, 10 }
p2 = { "blue", "red" }

test 1: ( 1, "red" )
test 2: ( 5, "red" )
test 3: ( 10, "red" )
test 4: ( 1, "blue" )
test 5: ( 5, "blue" )
test 6: ( 10, "blue" )

Note: I’m using the built-in Visual Studio 2010 unit testing, not NUnit or one of the many other unit test frameworks.

Edit:

I’m storing the possible values as enumerations in the test class, but it is also reasonable to use arrays. My goal is to automate the link between the source enumerations/arrays and the actual test. While my sample only has 2 parameters with 6 permutations, the actual set is much larger. I do not want to skip a scenerio just because I missed something in a manual conversion.

  • 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-15T02:54:26+00:00Added an answer on May 15, 2026 at 2:54 am

    The answer to your question is: You can use “Data-driven tests”. You can store your values in comma-seperated-value files, XML files, or SQL database files. I’ve been doing this with VS2k8, so your process with VS2k10 may be a little bit different.

    First, create a file with your test data. If you create a CSV file, it might look like

    param1, param2
    1, blue
    1, red
    5, blue
    5, red
    10, red
    10, blue

    Go to “Test View”, select the test you want to use the data with. In properties, click the ellipsis dots next to “Data Connection String”. Specify your file.

    Now, in your unit test code, you will specify the data from your file as
    testContext.DataRow("param1") and testContext.DataRow("param2").

    When you run the test, you will get a test result for each data row the test runs with. How convenient!

    Update If you want to automatically use Cartesian products of parameters that are kept as enumerations, you might want to use nested for loops like

    dim testResults as dictionary(of triplet,string)
    for each x as foo in fooCollection
    for each y as bar in barCollection
    for each z as foobar in foobarCollection
    Try
    ‘ test code
    testResults.add(new triplet(x,y,z),”PASS”)
    catch ex as exception
    testResults.add(new triplet(x,y,z),”ERROR: ” + ex.toString())
    End try

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

Sidebar

Related Questions

Ought I to unit test constructors? Say I have a constructor like this: IMapinfoWrapper
I have a unit test that works fine locally but when uploaded to TeamCity
Is it good practice to have a unit test that specifies how long a
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
I have a unit test where I have statically defined a quite large byte
I have a unit test (example is modified Test::Unit documentation ) require 'test/unit' class
I have a Boost unit test case which causes the object under test to
I have an extremely simple unit test. I'm not sure why it fails when
I have some kind of test data and want to create a unit test
I have 2 projects each one with its own unit test project, and one

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.