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

The Archive Base Latest Questions

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

I want to unit test my rendering engine for an ASP.NET app. I have

  • 0

I want to unit test my rendering engine for an ASP.NET app. I have some custom controls created in that app. Most of those control rely on having CreateChildControls() method called by the ASP.Net engine wheather during initial call or a postback.
When running a test CreateChildControls() does not get called and the control is in an “invalid” state.

As a workaround to get the tests going I explicitly call some other public method that calls EnsureChildControls() in it. This in effect causes CreateChildControls() to be executed and the control being initialized properly (just as it would normally when hosted on web server).
I would like to get rid of that extra method call and the control to still be in a proper state for testing.

Are there any elegant solutions to this problem?

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

    You could alternatively use reflection to call CreateChildControls directly, thereby escaping the need to use the public method to invoke it. That would be easy enough:

    var methodInfo = control.GetType().GetMethod("CreateChildControls", BindingFlags.Instance | BindingFlags.NonPublic);
    methodInfo.Invoke(control, new object[] { });
    

    You could embed this code somewhere so that you only need to do this once and reuse it.

    EDIT: You could have your test inherit from your control too, so you can invoke some of these methods directly. But you have to instantiate your control by instantiating the test and not the control, as in:

    public class CtlTest : Ctl
    {
      [Test]
      public void A()
      {
        var ctl = new CtlTest();
        ctl.RecreateChildControls(); //protected, but can be accessed because of inheritance
    
      }
    }
    

    HTH.

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

Sidebar

Related Questions

I have some kind of test data and want to create a unit test
I want to unit test the following ASP.NET MVC controller Index action. What do
I have a pseudo random number generator (PRNG) class that I want to unit
I want to unit test my code which will have to create a .java
I want to unit test the javascript I have embedded in the webapp portion
I want to unit test a Java application that fetches mails from an email
I have a class library I want to unit test using Microsofts unit test
I have a bunch of repository classes which I want to unit-test using Visual
I'm programming some unit test with the Google test framework. But I want to
I want to create a SQL Select to do a unit test in MS

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.