1

I have a scenerio where I have to get some data from the DB and display it in a Grid View in a Win forms app. I have written a unit test for Presenter mocking my repository and view. The test checks that the presenter calls the GetData() method of the repository and then calls the Bind(data) method of the view.

I have also another Integration test for the repository that verifies that if there is some data in the DB it is returned by the repository.

Now comes the part of testing my view. I can think of no way to test my form and check if it indeed binds data to the Grid view.

My question is that is there no way to test views in Winforms and will I always have to rely on manual testing for that?

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
Afraz Ali
  • 2,672
  • 2
  • 27
  • 47
  • Can't you simply bind the Grid and then check the data in the test method? I mean, it should be empty if the bind didn't work, right? – Tobberoth Dec 12 '13 at 10:50
  • @Tobberoth The gridview is an internal control of the form, for me to test if it contains data or not, I will have to expose it as a public control and then perform tests against it which to me seem unfair. Similar to why we should never create public methods or properties just to verify functionality of a class. – Afraz Ali Dec 12 '13 at 10:54
  • MVP ? http://stackoverflow.com/questions/4794121/model-view-presenter-in-winforms – yclkvnc Dec 12 '13 at 10:55
  • Yes I am using MVP, from the link that you have provided it seems that there is no need to test the implementation of view. If we have to test it then we will either have to test it manually or by some method exposing the grid to outside world which for me is not the correct way. – Afraz Ali Dec 12 '13 at 11:12

1 Answers1

1

I suggest you to test view and database only in acceptance tests. And you should understand, that this kind of tests very brittle and take lot of efforts to implement and support. Of course, manual UI testing is not very good idea - you should use some UI test automation tool like:

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
  • 1
    WoW! Thats what I was looking for. Never knew that these tools existed. Thanks lazyberezovsky for pointing out the great tools. – Afraz Ali Dec 12 '13 at 12:33