Writing unit cases for UI is not a very common development mode and also not very feasible but is possible. We often hear the merits of TDD from a backend developers. No doubt. TDD is good. People have seen the fruits of TDD over time.
Development in UI technology has been at a faster pace in recent times. Power of JavaScript is being appreciated not just for UI but as well for backend. Most of the web application handle its business logic in both back end and front end for load maintenance. There are also applications that uses UI for just mere representation for data. You don't want to invest time in unit test cases for merely representing UI. Rather I will focus on web applications that handles logic in front end.
Developing a web application
When developing web applications always use object oriented JavaScript. When you do procedural, over time you wont like what you have done.
When developing consider the below points:
Unit Testing Web Application
There are lot of test frameworks available in market for JavaScript. QUnit, YUI Test, JS Test Driver etc..
Developing your own test framework will also be an interesting piece of work. Write test cases even before you start writing code. Use cases are very important. If you jump into code your thinking will become narrow and will just focus on the existing requirement. Think wider and write test cases.
Okie. That was easy. You got some requirement wrote test cases and implemented. Now execution. Each test framework has its own way of executing test cases. Example, for QUnit you have to define a HTML page and initialize test classes from there. JS Test Driver has its own browser environment and console. Its all your choice. One major problem will be integrating test cases written in JavaScript with build cycle of your complete product suite. In next blog I will discuss QUnit and how it can be integrated with build.
Development in UI technology has been at a faster pace in recent times. Power of JavaScript is being appreciated not just for UI but as well for backend. Most of the web application handle its business logic in both back end and front end for load maintenance. There are also applications that uses UI for just mere representation for data. You don't want to invest time in unit test cases for merely representing UI. Rather I will focus on web applications that handles logic in front end.
Developing a web application
When developing web applications always use object oriented JavaScript. When you do procedural, over time you wont like what you have done.
When developing consider the below points:
- Understand and list possible use cases
- Identify and define classes
- Define Utility classes
- Define Factory classes
Unit Testing Web Application
There are lot of test frameworks available in market for JavaScript. QUnit, YUI Test, JS Test Driver etc..
Developing your own test framework will also be an interesting piece of work. Write test cases even before you start writing code. Use cases are very important. If you jump into code your thinking will become narrow and will just focus on the existing requirement. Think wider and write test cases.
Okie. That was easy. You got some requirement wrote test cases and implemented. Now execution. Each test framework has its own way of executing test cases. Example, for QUnit you have to define a HTML page and initialize test classes from there. JS Test Driver has its own browser environment and console. Its all your choice. One major problem will be integrating test cases written in JavaScript with build cycle of your complete product suite. In next blog I will discuss QUnit and how it can be integrated with build.