Activities
Compare unit testing, integration testing and system testing.
Modify the functions to use unit testing, integration testing and system testing below.
First, create a new folder in Visual Studio Code.
Create a file called
inventory_management.pyCopy the code block below, then save the file.
# Dictionary to store product quantities
inventory = {}
# Function to add products to the inventory
def add_product(product, quantity):
if product in inventory:
inventory[product] += quantity
else:
inventory[product] = quantity
# Function to sell products (decrease product quantity)
def sell_product(product, quantity):
if product in inventory and inventory[product] >= quantity:
inventory[product] -= quantity
else:
return "Insufficient stock"
# Function to check if a product is available
def check_availability(product):
return inventory.get(product, 0)
# Function to get total inventory value (simple example assuming fixed price for each product)
def total_inventory_value():
prices = {
'apple': 1.0,
'banana': 0.5,
'cherry': 1.5
}
total_value = 0
for product, quantity in inventory.items():
total_value += quantity * prices.get(product, 0)
return total_value
Now, create a new file in the same folder called
main.py
Any area that includes the comment "# TODO:" requires your attention.
In UNIT TESTING, "Assert" lines have been commented out. Uncomment each one (remove #), ONE AT A TIME, to test how it works.
For the functions AT THE BOTTOM of main.py comment all of them out EXCEPT FOR ONE AT A TIME.
Try unit_test() first, then integration_test(), then system_test()
Last updated