Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Tuesday, February 23, 2010 4:52 PM
hi all
how are you?
i wish anyone could help me in this problem
i am developing windows form application using visual studio 2008 and c# language
the windows form application has some controls on it with some event handlers that works on those controls
in the windows form application i have some functions that run inside the event handlers or in the windows form load event hanlder but these functions doesnt return any result
so how can i apply unit testing on those functions that doesnt return results using the Assert class
thanks a lot
Friday, March 5, 2010 11:11 PM ✅Answered
Good question. This is really the crux of a functional test vs. a unit test. You can certainly create a manual test and eventually a coded UI test which tests this scenario. However, a unit test is really used to quickly verify (without having to spool up the UI) that a method works. Much of how you do this is based on how your application is architected. For example, best practices state that you put virtually no logic in your user interface. So, with the MVC pattern for example, if you needed to kick off some logic raised by the changing of a value in a drop down box your form would raise an event that the model would respond to. In this case you can easily do this with a unit test because you can call the method which houses the logic directly. If you have logic in the actual interface itself this becomes a problem because to invoke the method, and put it in an environment that simulates a runtime environment you have to create an instance of the windows forms class which contains the method. At this point the recommended approach is to create a coded UI test and not try to test anything in the user interface with a unit test.
I know this was a long winded response but I hope it helps to explain the argument of one way versus another.
Jeff Levinson | Team System MVP
Tuesday, February 23, 2010 11:14 PM | 1 vote
Hi. In general you can't - directly that is. If those functions perform some operation where they are modifying some other properties or values that you have access to you need to check those properties or values independently. So, the pseudo-code might look something like this:
Call the method
Retrieve the value of the controls/properties that changed
Perform an Assert on the changed value
That's really all you can do. The other option (not knowing how these methods that you call are constructed) is to re-write the method so that they do return a value that you can check. This may be as simple as a bool if the method succeeded or a 1 or a 0 for a failure or something like this. This is part of the philosophy of making your code more testable and obviously void methods aren't as testable as those that return a value.
Hope this helps a bit.
Jeff Levinson | Team System MVP
Tuesday, March 2, 2010 11:22 AM
hi thx for your reply
if i have a windows form with drop down list and i want to choose an item in the drop down list
can i invoke that event using the unit testing or it should be done using manual testing
for example: i
f i have a drop down list with two items in it .
the first item is customer profile and the second item is credit file
i have an event that is wired to the drop down list when i choose any item
and that event fires when i choose any item in the window form using the interface
can i invoke that event using the unit testing or it should be done using manual testing
thx a lot