Project: Csi College of Engineering
Project: Csi College of Engineering
Project
Design a test case for testing the e-commerce application
Team Members:
Balakamatchi.S- 710622104007
Bharath.N- 710622104009
Deepak.R- 710622104010
Deepesh Kumar.T- 710622104011
Dharshini.S- 710622104013
Abstract:
This project provides an implementation of a simple
AmazonECommerceApp that simulates core functionalities
such as user registration, login, product search, adding
products to a cart, and checkout. The system is developed
using Python and tested using the unittest module. The
unittest framework ensures that various scenarios, including
user login success/failure, product search, cart management,
and checkout processes, work correctly. This document
outlines the application code, testing environment, hardware
and software requirements, and key conclusions derived from
the test results.
Design a Test Case for testing the
e-commerce application
Introduction:
The AmazonECommerceApp simulates an e-commerce
application where users can register, log in, search for
products, add them to their cart, and perform checkout
operations. The application is designed to provide essential e-
commerce functionalities while remaining simple for
educational purposes. To verify the correctness of the
implementation, the code is tested using Python's unittest
framework. This allows for the automation of test cases to
ensure that critical components like user login, product
management, and checkout work as expected. In this
document, we describe the application's functionality, required
hardware and software, and the results of the test cases.
Hardware Requirements:
• Processor: Minimum dual-core processor (2 GHz or
faster)
• RAM: 4 GB or more
• Storage: 500 MB of free space
• Operating System: Windows, macOS, or Linux with
Python installed
• Network: Internet connection for package installations
(if needed)
Software Requirements:
• Operating System: Any OS with Python 3.x installed
• Python Version: 3.x or above
• Libraries:
o unittest (built-in Python module)
o Text editor or IDE (e.g., Visual Studio Code,
PyCharm)
Application Features:
• User Registration: Allows users to register with an
email and password.
• User Login: Users can log in with valid credentials.
Invalid login attempts are handled.
• Product Search: Users can search for products using
keywords (e.g., "laptop").
• Cart Management: Users can add products to their cart
and view the contents.
• Checkout: Simulates a checkout process by providing
shipping and payment information.
Test Cases:
The unittest module is used to verify the following:
1. User Login Success: Tests if a user can log in with valid
credentials.
2. User Login Failure: Tests the failure of login with
invalid credentials.
3. Product Search: Tests if the product search functionality
works correctly.
4. Add to Cart: Tests if a product is successfully added to
the user's cart.
5. Checkout: Tests the successful completion of the
checkout process.
Algorithm:
STEP 1: AmazonECommerceApp Class
• Initialization (__init__):
o Initialize an empty dictionary users to store user
details.
o Initialize an empty list cart to store added products.
• Register User (register_user):
o Accept email and password.
o Add the user to the users dictionary.
o Return success response.
• Login (login):
o Accept email and password.
o Check if the email exists in users and if the
password matches.
o Return success if valid, or failure if invalid.
• Search Product (search_product):
o Accept query.
o Simulate a product search by returning a product list
if the query contains the word "laptop", else return
an empty list.
• Add Product to Cart (add_product_to_cart):
o Accept product_id.
o Add the product_id to the cart.
• View Cart (view_cart):
o Return the contents of the cart.
• Checkout (checkout):
o Accept shipping_address and payment_info.
o Simulate a successful checkout process and return a
success message.
• Delete User (delete_user):
o Accept email.
o Remove the user from the users dictionary if the
user exists.
STEP 2: TestAmazonECommerceApp Class (Unit Testing)
• setUp Method:
o Initialize the test environment by creating an
instance of AmazonECommerceApp.
o Register a test user using register_user with email
"[email protected]" and password
"SecurePassword123".
• Test Case: Successful Login (test_user_login_success):
o Perform a login with valid credentials.
o Assert that the login is successful and returns the
correct message.
• Test Case: Failed Login (test_user_login_failure):
o Perform a login with an invalid password.
o Assert that the login fails and returns an "Invalid
credentials" message.
• Test Case: Search Product (test_search_product):
o Perform a search for "laptop".
o Assert that the result contains at least one product
and the product name contains "laptop".
• Test Case: Add Product to Cart
(test_add_product_to_cart):
o Add a product with the ID "product_id_123" to the
cart.
o Assert that the product is in the cart.
• Test Case: Checkout Process (test_checkout_process):
o Add a product to the cart.
o Perform the checkout with a shipping address and
payment information.
o Assert that the checkout is successful and the order
is placed.
• tearDown Method:
o Clean up by deleting the test user after each test.
STEP 3: Main Method (if _name_ == '_main_')
• Run the unit tests using unittest.main().
Flowchart:
Code:
import unittest
def view_cart(self):
return {"products": self.cart}
class TestAmazonECommerceApp(unittest.TestCase):
def setUp(self):
"""Initialize the test environment."""
self.app = AmazonECommerceApp()
self.app.register_user("[email protected]",
"SecurePassword123")
def test_user_login_success(self):
"""Test successful login with valid credentials."""
result = self.app.login("[email protected]",
"SecurePassword123")
self.assertTrue(result['success'])
self.assertEqual(result['message'], "Login successful.")
def test_user_login_failure(self):
"""Test login failure with invalid credentials."""
result = self.app.login("[email protected]",
"wrongpassword")
self.assertFalse(result['success'])
self.assertEqual(result['message'], "Invalid credentials.")
def test_search_product(self):
"""Test searching for a product."""
results = self.app.search_product("laptop")
self.assertGreater(len(results), 0)
self.assertIn("laptop", results[0]['name'].lower())
def test_add_product_to_cart(self):
"""Test adding a product to the shopping cart."""
self.app.add_product_to_cart("product_id_123")
cart = self.app.view_cart()
self.assertIn("product_id_123", cart['products'])
def test_checkout_process(self):
"""Test the checkout process."""
self.app.add_product_to_cart("product_id_123")
result = self.app.checkout("123 Main St",
"payment_info")
self.assertTrue(result['success'])
self.assertEqual(result['message'], "Order placed
successfully.")
def tearDown(self):
"""Clean up after tests."""
self.app.delete_user("[email protected]")
if __name__ == '__main__':
unittest.main()
Code Implementation:
Output:
Output Explanation:
Dots (.): Each dot represents a test that passed. In your case,
there are five dots for five successful tests.
Ran 5 tests: This line confirms that a total of five tests were
executed.
Time Taken: Indicates how long it took to run the tests.
OK: This final status indicates that all tests were successful
without any failures or errors.
Conclusion:
The AmazonECommerceApp provides a simple but functional
prototype of an e-commerce system with core features like
user authentication, product search, cart management, and
checkout. The use of unittest ensures that the application
behaves as expected under different conditions. The
implementation and tests highlight how various e-commerce
functionalities can be modeled and tested in Python, providing
a solid foundation for expanding the app further.
The project demonstrates effective use of object-oriented
programming principles and unit testing to build a reliable and
maintainable application.