Testing Cookies

Problem

You want to test a servlet that uses cookies.

Solution

Write a ServletTestCase that tests if your servlet correctly handles creating and managing cookies.

Discussion

Cookies are small pieces of information passed back and forth between the web server and the browser as a user navigates a web application. Web applications commonly use cookies for session tracking because a cookie’s value uniquely identifies the client. There is a danger for a web application to rely solely on cookies for session tracking because the user may, at any time, disable cookies. For this reason, you must design your web application so that your web application still works if cookies are disabled.

Example 7-5 shows how to write a test for a servlet that uses cookies to keep track of how ...

Get Java Extreme Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.