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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:41:15+00:00 2026-05-15T16:41:15+00:00

I’m trying to create a test class which organizes its test methods using inner

  • 0

I’m trying to create a test class which organizes its test methods using inner classes. I would like for this class to be abstract with the ability to set a static property so this property can be injected. Here’s an example of what I’m talking about:

[TestClass]
public abstract class BaseUnitTest
{
   public static string InjectedProperty;

   public static string GetInjectedString()
   {
      return InjectedProperty;
   }

   [TestClass]
   public class WhenFoo
   {
      [TestMethod]
      public void TestFoo()
      {
         string str = GetInjectedString();
      }
   }
}

[TestClass]
public class DeriverdUnitTest : BaseUnitTest
{
   [ClassInitialize]
   public void SetUp()
   {
      InjectedProperty = "Injected Property";
   }
}

However, I don’t see a DerivedUnitTest+WhenFoo+TestFoo() class show up in my unit test view. I’m using Visual Studio 2010. I’m guessing when I override BaseUnitTest, I don’t override its inner classes as well. I suppose I could make its inner classes abstract and override them later, but as the complexity of my test class increases this will get really annoying. Could somebody please explain why this is occuring and how I can fix it?

Thanks.

Edit:

I feel like I need to better explain my reasons for wanting to do this. We’d like to implement a testing standard which is very verbose in its naming. Therefore a test class would look something like this:

[TestClass]
public abstract class BaseUnitTest
{
   public static string InjectedProperty;

   public static string GetInjectedString()
   {
      return InjectedProperty;
   }

   [TestClass]
   public class WhenFooIsCalled
   {
      [TestClass]
      public class AndTheArgumentIsNull
      {
         [TestMethod]
         public void AnArgumentNullExceptionShouldBeThrown()
         {
            string str = GetInjectedString();
         }
      }
   }
}

The advantage of this is when you open up the test view in Visual Studio and display the method name and class name columns you get something that looks like this:

BaseUnitTest+WhenFooIsCalled+AndTheArgumentIsNull AnArgumentNullExceptionShouldBeThrown()

This makes it a lot easier to glance to tell what a failing test among a few hundred pass tests is supposed to do.

The main reason I want to be able to override the abstract BaseUnitTest is because when I do all of the tests which were contained in the BaseUnitTest are all added to the DerivedUnitTest and show up in the Test View in Visual Studio.

Thanks again.

  • 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-15T16:41:16+00:00Added an answer on May 15, 2026 at 4:41 pm

    Nested types don’t work that way. You can’t “override” types.

    It’s not clear what you’re trying to achieve here, but I don’t think it’s going to work.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm trying to select an H1 element which is the second-child in its group
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post

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.