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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:42:32+00:00 2026-06-18T03:42:32+00:00

I was reading this topic , which is about using reflection to test a

  • 0

I was reading this topic, which is about using reflection to test a private variable…

But I don’t have such problems in my unit test and my code is totally testable.

The only problem is I figured out, it’s very time consuming when doing an assertion for each property of a complex object with an expected result; especially for a list of complex objects.

Since it is a complex object, doing a normal Assert.AreEqual is not going to give me a correct result unless I am implementing IEquality for each of the objects.

But even if I do so, this won’t tell me which property/field’s name, expected value and actual value during assertion.

Correctly, we are manually putting each of the property values into a list and doing a single CollectionAssertion, but this is still time-consuming and when the assertion occurs it only tells me the index of a element value is not equal; it wont’ tell me the property name. Which makes it very difficult to debug (I had to go to debug mode and look at the element in collection).

So I wonder, if I write a recursive reflection method that will do assertion on two complex objects, which will tells me every property name, expected value, actual value.

Is that a good practice or bad practice?

  • 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-06-18T03:42:34+00:00Added an answer on June 18, 2026 at 3:42 am

    IMHO, it is a bad practice because:

    • Reflection code is slow and difficult to write right
    • It is even more difficult to maintain and such code may not be refactor-friendly
    • Reflection is slow, unit tests shall be fast
    • It also doesn’t feel right

    To me this looks as if you are trying to plug a hole, rather than fix a problem. In order to fix the problem I can suggest to segregate a large and complex class into a set of smaller ones. If you have many properties – group them into individual classes


    So that such class

    class Foo
    {
        T1 Prop1 {get; set;}
        T2 Prop2 {get; set;}
        T3 Prop3 {get; set;}
        T4 Prop4 {get; set;}
    }
    

    Would become

    class Foo
    {
        T12 Prop12 {get; set;}  
        T34 Prop34 {get; set;}  
    }
    class T12
    {
        T1 Prop1 {get; set;}
        T2 Prop2 {get; set;}
    }
    class T34
    {
        T3 Prop3 {get; set;}
        T4 Prop4 {get; set;}
    }
    

    Note, that the Foo has now got only one property (that is a “grouped” representation). If you can group the properties in a way, so that any state change would be localised to a specific group – your task becomes much more simplified. You can then assert that a “grouped” property is equal to the expected state.

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

Sidebar

Related Questions

I've been reading everything I can find on here about this topic but am
After reading this article I don't have a clear answer: http://palizine.plynt.com/issues/2010Oct/bypass-xss-filters/ Will browsers interpret
I was reading this blog post on git which talks about various branching strategies.
Reading online about this topic is confusing. Is there a way to cut around
There are many discussions on this topic already, but I am all about flogging
ive been reading about this topic and didnt get the specific info for my
I've been reading this article about closures in which they say: all the plumbing
I have been reading many topics about filtering SQL queries, but none seems to
Reading this article http://support.microsoft.com/kb/813878 I have a question: Where can I get ipseccmd.exe for
I was reading this article which mentions storing 1Million keys in redis will use

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.