Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have a method that looks something like this
C#
public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("someName", this.someName);
            info.AddValue("someName1", this.someName1);
            
            base.GetObjectData(info, context);
        }


If I'm unit testing this method, should I just leave it as it is or should I try and test 'base.GetObjectData()' by iteself by refactoring it out somehow?
How would I unit test this method?

I included a statement that now checks to see if a parameter in null.
C#
if (info == null)
           {
               throw new ArgumentNullException("info");
           }

and I included a test like so
C#
[TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void GetObjectData_NullParameters_ThrowsException()
        {
            Respondent myRespondent = new Respondent(new RespondentInformation());
            SerializationInfo info = null;
            StreamingContext context = new StreamingContext();
            myRespondent.GetObjectData(info, context);

        }


but isn't there more to test? What else can I test? Shouldn't I be testing the base.GetObjectData' method?
Posted
Updated 30-Oct-12 13:05pm
v2
Comments
Sergey Alexandrovich Kryukov 30-Oct-12 19:05pm    
What difference may it make, ever? Such call is the most usual thing; how could it possibly make testing more difficult?
--SA

1 solution

IMHO:
1. You should test the base class independently, before you test the derived class.
2. Testing for a null parameter is nice, but you should also test that, given valid parameters, the result of your function (not this one, but others that are not void) is the one you expect, and the state of the object after calling the method is also the one you expect.

Spend a few hours reading on unit tests: it will pay off.

Hope this helps,
Pablo.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900