Should I be testing this class?

I know this could be a very simple question, but I have a little bit of mind at this point. Should I be unit testing this class.

public class MapinfoWindowHandle : IWin32Window
    {
        IntPtr handle;

        public MapinfoWindowHandle(IntPtr mapinfoHandle)
        {
            this.handle = mapinfoHandle;     
        }

        #region IWin32Window Members

        IntPtr IWin32Window.Handle
        {
            get { return this.handle; }
        }

        #endregion
    }

      

If I should be what should I be tested over?
I use it like this:

IntPtr handle = new IntPtr(100);
myform.show(new MapinfoWindowHandle(handle));

      

+1


source to share


6 answers


The only thing I can see is make sure you pull out the handle that you entered through your constructor. I know it's obvious that you implemented it this way, but the test will convince you that it stays that way. I would check this just because you are injecting it through the constructor. If it was just {get; set; } I probably wouldn't.



 [TestMethod]
 public void ConstructorTest()
 {
      IntPtr handle = new IntPtr(100);
      MapinfoWindowHandle winHandle = new MapinfoWindowHandle(handle);
      Assert.AreEqual( handle, ((IWin32Window)winHandle).Handle );
 }

      

+4


source


I would for sure try trying to build it with NULL (0) or INVALID_HANDLE_VALUE (-1) and maybe run it / both if needed (not clear if the class can be initialized with IntPtr. Zero, but it's pretty sure that -1 will be invalid.



+2


source


Yes. If the class is worth writing, it's worth checking

+1


source


The pragmatist in me says "no" because the class does nothing, so don't check "anything". But make sure you can still check it out, for documentation purposes only, and as a contract for future developers.

0


source


GUI code is notoriously difficult to unit test. I never found it too useful in my applications. Just keep your business logic outside of your GUI so you can easily test this. I usually test gui code with either manual or automated integration / acceptance tests. It is difficult to write a test to make sure something "looks right".

0


source


Yes, write down the test. If someone later changes the code or adds new code to it, you have at least one test to ensure that the class works as intended.

0


source







All Articles