Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: testing unit
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
[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 30-Oct-12 11:26am
Edited 30-Oct-12 14:05pm
v2
Comments
Sergey Alexandrovich Kryukov at 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

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

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 334
1 Kornfeld Eliyahu Peter 325
2 Maciej Los 239
3 OriginalGriff 188
4 King Fisher 185
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 31 Oct 2012
Copyright © CodeProject, 1999-2014
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