writing Unit tests for an GUI C# application possible?

690 views
Skip to first unread message

Willimien Willimien

unread,
Nov 12, 2014, 11:47:04 AM11/12/14
to nunit-...@googlegroups.com
Hi there,
 
As a testengineer I am told by the Developer that writing Unit tests for a GUI C# (.Net) application is not possible. (Be it using Nunit or some other tool.)
 
I rather doubt the claim of the developer.
 
I came to this forum through various google searches.
Hopefully you guys can clear this for me... possible or not?
 
Thanks.
Willimien
 

Charlie Poole

unread,
Nov 12, 2014, 1:42:30 PM11/12/14
to NUnit-Discuss
Let's assume your developer is reasonably smart. :-)

In that case, he is probably not saying you can't write tests of a Gui
- obviously you can - the question is whether they are unit tests or
not.

In his favor, hardly anyone who claims to write Gui unit tests does
so. What they do is to drive the entire application through the Gui.
That's not a unit test.

I'm a big advocate of unit-testing the Gui in apps where it's
critical. Think medical equipment software, where medical techs use
what the gui is telling them to decide where to cut or where to aim
the radiation!

In such a case, we need to know that the Gui works. And whenever we
_really_ need to know that something works, we need to test it.

A true unit test of the Gui has to replace the entire back end with a
test double of some kind. This is a lot of work. So, while you
definitely can unit-test the Gui and definitely should do it in
safety-critical situations, it's usually not worth the effort in
typical business applications.
> --
> You received this message because you are subscribed to the Google Groups
> "NUnit-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nunit-discus...@googlegroups.com.
> To post to this group, send email to nunit-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/nunit-discuss.
> For more options, visit https://groups.google.com/d/optout.

Rob Prouse

unread,
Nov 12, 2014, 2:05:39 PM11/12/14
to nunit-...@googlegroups.com
It also depends on how he defining writing tests for a GUI app. If he means that it is hard to write unit tests that exercise and test the GUI, then he is right. That is more in the domain of integration testing. There are tools that allow you to write tests and exercise the GUI, but they tend to be fragile and in my opinion not worth the effort.

If he is trying to tell you that he cannot write ANY test for the application because it is a GUI application, then he is wrong, or he has architected the application very poorly. For example, one of the side projects I am working on is WPF application that talks to a REST backend. In that application, I have nearly no code in the UI layer and manage to have a very high level of test coverage of the code. It just takes a decent architecture and some dependency injection.

Chris Raplee

unread,
Dec 16, 2014, 5:19:52 PM12/16/14
to nunit-...@googlegroups.com
Microsoft has a tutorial entitled, "Verifying Code by Using UI Automation" which discusses the concepts involved in Coded UI Tests, which are rather different than Unit Tests but certainly fill a niche. 

Best of luck, 
Chris
Reply all
Reply to author
Forward
0 new messages