Click here to Skip to main content
13,042,630 members (84,369 online)
Rate this:
Please Sign up or sign in to vote.
I have a method that looks something like this
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.
if (info == null)
               throw new ArgumentNullException("info");

and I included a test like so
        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 30-Oct-12 10:26am
Updated 30-Oct-12 13:05pm
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?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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,

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 31 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100