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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:44:38+00:00 2026-06-02T21:44:38+00:00

As titled. I have a class that implement IComparable which need for sorting. I

  • 0

As titled.

I have a class that implement IComparable which need for sorting. I wrote all unit testing against all methods. But then is it make sense to write a unit test to check does it implement IComparable?

Because with the interface when sorting in UI it won’t work. But compile it will still work. So if I have such test case, it can be catch if anyone removed that interface.

My class is something like:

 public class ComparableCustomType: IComparable
    {
        private readonly someFields;

        public ComparableCustomType(AnotherBusinessObject obj)
        {
              //Do some parsing against the obj
        }

        public int CompareTo(object obj)
        {
             //Some custom sorting logic
        }
    }

Basically my test case will be:

[TestMethod]
public void CompareTo_IsImplementIComaparable()
{
      IComparable comparable = Isolate.Fake.Instance<ComparableCustomType>();
      Assert.AreNotEqual(null, comparable);    
}

EDIT: This is how I use this property….(or I should say that’s how the person use this property…)

public class CustomItem{

    private AnotherBusinessObject anotherBusinessObj = null

    public CustomItem(AnotherBusinessObject obj)
    {
        this.anotherBusinessObj = obj;
    }

    public ComparableCustomType {
        get { return new CamparableCustomType(this.anotherBusinessObj); }
    }

    public string SomeOtherProperty {get;set;}

    publci int AnotherProperty {get;set;}

}

public ObservableCollection<CustomItem> MyCustomCollection {get;set;}

Then this collection will databinds to my GridView…. so it will automatically generates all columns…..

  • 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-02T21:44:44+00:00Added an answer on June 2, 2026 at 9:44 pm

    To quickly summary my answer, I say no, it doesn’t make much sense to write a unit test to check what a class implements/inherits. IMO, unit tests should be written to test logic/functionality, not type. That’s pretty much like writing a test to make sure you can instantiate a constructor. Usually something like that is overkill and I believe that this case is overkill as well.

    Your code should be checked at compile time. You can apply this constraint when the object is instantiated (if this is possible for the way you’re using your objects).

    Let’s say that your class that implements IComparable is called FooComparable:

    IComparable foo = new FooComparable();
    

    Likewise, if you have already instantiated the object and it’s sole function isn’t necessarily an IComparableobject you could apply a couple other constraints. Let’s say maybe you have your FooComparableand you want to make sure it’s IComparablebefore binding it to a control, you could do something like this:

    IComparable dataSource = fooObj;
    

    If you try this and FooComparable does NOT implement IComparable, the compiler will complain. Maybe you should provide a code example of how you’re using the class so we could provide more suggestions.

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

Sidebar

Related Questions

I have this ConstantData class which holds my JSON indexes, I need to pass
All, i have the following model defined, class header(models.Model): title = models.CharField(max_length = 255)
I have a custom Image class that I am using to store individual image
I have a List<T> where T is a class that exposes a Username property.
As titled. We all know if we want a class to be comparable and
I have a a number of UIViewControllers in my project that implement the UITableViewDataSource
I have a class that I am binding to my view model. It is
While developing a game I have designed a class that in normal operation has
I have successfully been able to implement the addition of new artist entries which
Imagine I have a list of objects that implement an interface called ISummary The

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.