This article is the first in a series about Test Driven Development. A test is an example of what a program should do. Examples make the requirements concrete, so they become easier to understand. I will show how examples can be used for requirements, manual testing and unit testing.
I am currently working on automatic order handling for a client. I will implement a servlet with the following tasks:
1. Decode input parameters from a web page.
2. Generate an encrypted license with some of those parameters.
3. Store the license in a database. I can model this database as I want.
4. Store customer data in another database. This database schema is "carved in stone".
5. Send the license as an email to the user.
This is a small project, where I will implement, test and deploy the servlet myself. If it doesn't work, my client will lose customers, and I will be responsible.
So how can I make sure this doesn't happen?
I don't trust myself to make so good quality that there won't be any problems. So, I need to do thorough testing. I will make unit tests, but how do I make good ones?
Unit testing is important, but it's not enough. There are always some issues that don't show up until manual testing. I also need to test the integration between my program and other components manually. But how do I make good manual tests? Do I need to write a formal test specification for this simple program?
I think I do. I need to discuss the requirements with my client, and some examples of what the program is supposed to do is the best way to do that. By making a few concrete examples, I can make sure there are no misunderstandings, and that no requirements are missing. I'm sure there will be some misunderstandings anyway, but that's why I'm going to test it.
I'll use this test specification both for manual testing and as basis for the unit tests. That way, I'll have good unit tests that cover the functionality well, and there hopefully shouldn't bee too many surprises when it comes to integration testing.
I start by writing down 2 examples that the servlet should handle. For each example, I will list the input parameters, output values and any changes to the databases. It doesn't take long to write these down on a piece of paper, and it will be very much worth the effort.
Example 1: A customer orders 1 license of type "Enterprise"
Input
License Content
Insert a license with the following values:
(I need to ask the client about this.)
Email
Input
Insert a license with the following values:
(Ask the client.)
Email
When I talked to the client, the he pointed out that it is possible to order multiple licenses of the "Enterprise" product at once. I hadn't though about that. Together, we discussed how to handle this.
In the next article, I will write about how to implement and unit test the servlet.
I am currently working on automatic order handling for a client. I will implement a servlet with the following tasks:
1. Decode input parameters from a web page.
2. Generate an encrypted license with some of those parameters.
3. Store the license in a database. I can model this database as I want.
4. Store customer data in another database. This database schema is "carved in stone".
5. Send the license as an email to the user.
This is a small project, where I will implement, test and deploy the servlet myself. If it doesn't work, my client will lose customers, and I will be responsible.
So how can I make sure this doesn't happen?
I don't trust myself to make so good quality that there won't be any problems. So, I need to do thorough testing. I will make unit tests, but how do I make good ones?
Unit testing is important, but it's not enough. There are always some issues that don't show up until manual testing. I also need to test the integration between my program and other components manually. But how do I make good manual tests? Do I need to write a formal test specification for this simple program?
I think I do. I need to discuss the requirements with my client, and some examples of what the program is supposed to do is the best way to do that. By making a few concrete examples, I can make sure there are no misunderstandings, and that no requirements are missing. I'm sure there will be some misunderstandings anyway, but that's why I'm going to test it.
I'll use this test specification both for manual testing and as basis for the unit tests. That way, I'll have good unit tests that cover the functionality well, and there hopefully shouldn't bee too many surprises when it comes to integration testing.
I start by writing down 2 examples that the servlet should handle. For each example, I will list the input parameters, output values and any changes to the databases. It doesn't take long to write these down on a piece of paper, and it will be very much worth the effort.
Example 1: A customer orders 1 license of type "Enterprise"
Input
product_id = (ask the client what the product id is)I have already identified a very important question I need to ask my client: What are the product ids that the servlet will receive?
quantity = 1
company_name = Dot Com Inc
email = john@dotcom.com
License Content
type = EnterpriseLicense Database
company name = Dot Com Inc
email = john@dotcom.com
expires = 3/25/2009
Insert a license with the following values:
type = EnterpriseCustomer Database
company name = Dot Com Inc
email = john@dotcom.com
date = 3/25/2008
expires = 3/25/2009
(I need to ask the client about this.)
to = john@dotcom.comExample 2: A customer orders 1 license of type "Basic"
subject = License
content = Please find attached an Enterprise license to
Dot Com Inc and email john@dotcom.com.
attachment = enterprise.lic
Input
product_id = (Ask the client)License Content
quantity = 1
company_name = Dot Com Inc
email = john@dotcom.com
type = BasicLicense Database
company name = Dot Com Inc
email = john@dotcom.com
expires = 3/25/2009
Insert a license with the following values:
type = BasicCustomer Database
company name = Dot Com Inc
email = john@dotcom.com
date = 3/25/2008
expires = 3/25/2009
(Ask the client.)
to = john@dotcom.comNow, I need to go through these examples with my client.
subject = License
content = Please find attached a Basic license to
Dot Com Inc and email john@dotcom.com.
attachment = basic.lic
When I talked to the client, the he pointed out that it is possible to order multiple licenses of the "Enterprise" product at once. I hadn't though about that. Together, we discussed how to handle this.
In the next article, I will write about how to implement and unit test the servlet.
Comments