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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:43:30+00:00 2026-05-16T17:43:30+00:00

I’m interested in being able to instantiate multiple testfixtures with constructor arguments passed to

  • 0

I’m interested in being able to instantiate multiple testfixtures with constructor arguments passed to it at runtime by a static method or property returning an IEnumerable.

In Nunit 2.5 they introduced parameterised tests and test fixtures. These allow you to write a single test and run it with several inputs provided using the TestCase attribute, and write a single test class and instantiate multiple instances of it with different constructor arguments respectively.

In addition to this, it is possible to create several test cases based on the output of a property or method, using the TestCaseSource attribute. This will use the output of a method/property that implements IEnumerable to create a set of testcases, one per object in the list. This is what I’d like to be able to do, but at the fixture level not the Test level.


Some background on my use case:

I’m testing simulation software, and a ‘simulation environment’ that must be loaded (from a serialized object) before any simulations can be run. There are about 5 different types of sim, so my test class has 5 test methods (one for each type of sim). I’m using inheritance currently (instead of parameterised fixtures) to run the test cases under several (a half dozen or so) simulation environments, which have been taken from production data.

My trouble springs from the fact that in a recent attempt to increase code coverage, we automatically generated all possible combinations of simulation components, resulting in 100+ sim environments. I don’t want to create inherited classes for each of these so instead I’m using TestCaseSource with a property that returns all the workspaces in a folder, and modifying the tests so they (re)load the sim environment within the test itself for each testcase.

Ideally I’d like to have one fixture per simulation environment, and determine how many/what these are at runtime. I know I can do the former via hardcoding the sim environment paths into 100+ TestFixture attributes, can I do the latter?

  • 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-16T17:43:30+00:00Added an answer on May 16, 2026 at 5:43 pm

    I emailed the Nunit-Discuss list about this and got the below response from Charlie Poole. In brief, this isn’t possible yet, but is being looked at for future versions of Nunit.

    Hi,

    Simply stated, what you want is
    coming, but it’s not here yet.
    Parameterized fixtures are (as you
    have discovered) limited by the fact
    that you can only use arguments that
    are permitted in attributes. We’d like
    to have a way that allows use of
    properties and methods as for test
    cases but fixtures are a bit more
    complicated, since the type may be
    generic.

    Have you considered using a generic
    fixture as a workaround? You could
    pass in the environment as a Type (or
    Types) and any constructor arguments
    as non-type arguments. I don’t know
    your app, so take this with a grain of
    salt, but how about something like…

    [TestFixture(typeof(Environment1), 42, "string")]
    public class TestClass<T>
    {
        IEnvironment env;
    
        public TestClass(int n, string s)
        {
           env = new T( n, s);
        }
        ...
    
    }
    

    Note that this is “maillistcode” so
    may not work. 🙂

    Charlie

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

Sidebar

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.