MOCK Your GUI
I love this caption. I’m sitting here picturing a developer looking at a screen someone designed and saying something like, "My 2 year old son could design something better than that with crayons." But that’s not where I’m going with this.
In my experience, the most difficult piece of software to test is the User Interface. Graphical User Interfaces (GUI) are the most difficult. Generally, you have to have someone interact with the GUI in order to make it perform. Capturing results and handing events are often difficult problems to resolve.
There are a number of commercial and open systems tools operating as Robots that exercise a GUI and are able to test the results of the actions. Depending on the method of implementation these tools may be fragile as the GUI components are maintained in a design tool. Sometimes control identifiers (exposed in the DOM) are modified through you designers, causing robots to no longer be able to locate the targets for actions.
This is an area where Java developers exceed. The Model View Controller (MVC) pattern has been popular for years in the Java world. The MVC pattern separates the data (model), presentation (View) and interaction between the two (Controller) into different processes.
This pattern has a number of benefits. A popular benefit is the ability to re-use logic in the controller and the model, and represent that data in different views. A View can be a web form, a thick client GUI form, or even a console.
For me, the biggest benefit of a pattern such as MVC is the ability to MOCK the view. To create a MOCK in software, you create an object that has the same interface as the object being mocked. The difference is that it doesn’t really have to connect to anything. However, having a MOCK of a view allows a developer to fully test interaction of a view with the Model and the Controller, without having any interaction with a user or robot. In fact, it doesn’t even require a web server.
Using a MOCK you can fully test your controller and the View Interface. Once complete, a fully functional View can be created for any number of User Interfaces with great success. MOCKs work nicely with JUnit and NUnit.
Microsoft has recently embraced MVC, and it is becoming more popular. They also have Model ,View, Presenter (MVP) which is quite similar. The current MS pattern, working closely with Silverlight, is Model, View, View-Model. Again, these patterns lend themselves to being mocked.
So, MOCK your GUI, and gain a high level of confidence for the correctness of your code, and the ability to change it quickly.
Reader Comments:
Stephen Writes Regarding Business Rules:
I don both database and developer hats over the past 12 years. Every part of this week long adventure reminded me of our US Congress and their attitude “My way or the highway.” There was never any statements about doing logic in an area that pertained to that area.
A set of business rules could be constructed for proper email address. Should those live in the DB, or do they fare better in the UI? Could you determine that the “@” sign is missing before interacting with the DB?
My current employer is of the mindset that ALL rules are driven in the db and I could show some dynamic SQL all over our audit process that screams “What were you thinking?”
What we do is workflow processing and our Sprocs prove that we are very good at waterfall methodology. He who must be obeyed has no desire to investigate why our process is workflow, let alone how to get good at it.
From my perspective you do the process that fits the engine and when another engine is better you incorporate it into your process. Would you define that SQL Server is your choice for file movement from folder in to folder out, or would you consider PowerShell better for that?
Russell Adds Options Prior to CASE Statement
Don’t forget the characteristic functions, of which CHARINDEX was only one choice. See Joe Celko’s brief mention.
There are a lot of ways to use MOCKing in software development. Share your experience with our readers. Send an email to btaylor@sswug.org. Feel free to ask for discussions on other topics as well.
Cheers,
Ben
$$SWYNK$$
Featured Article(s)
Sharepoint (Part 1 of 3)
In this session, attendees will learn the basics of Microsoft Windows SharePoint Services (WSS) and Microsoft Office SharePoint Server (MOSS). This session will cover some of the basic use-cases for both WSS and MOSS, and will discuss when one should be chosen over the other. This session will also demonstrate a commercial application that is based on the MOSS platform.
Featured White Paper(s)
Storage Optimization
Written by AvePoint
Microsoft SharePoint Server 2010, the latest release of M… (read more)
Featured Script
How to use LIKE and wildcard ranges
Some samples of how to use wildcard ranges, like ‘How do I find values that has ONLY digits (0-9) from a char field’ and vari… (read more)