In this lesson, you will learn how to test the application and write its instructions effectively. Testing is an essential part of software development that helps ensure a reliable and user-friendly experience.
Testing the application is vital for any project. For example, imagine you have repaired your bike after fixing a flat tire. Before riding it again, you check if everything functions properly. This concept applies similarly to testing your Personal Expense Tracker. Ensuring that your app works as intended is the first step towards success.
When you test the application, you address potential issues early. This approach saves time and resources later. Additionally, it provides a smoother experience for end-users. Always remember that thorough testing leads to better software performance.
File: test_expense_tracker.js
// Function to test the application
function testApplication() {
// Check if totals are calculated correctly
const totals = calculateTotals();
console.log('Total Income: $' + totals.income);
console.log('Total Expenses: $' + totals.expenses);
// Validate user input
const validInput = validateInput("Coffee", 5);
console.log('Is input valid? ' + validInput);
// Display expenses
displayExpenses();
}
testApplication();
Total Income: $1000
Total Expenses: $150
Is input valid? true
This code tests crucial functionalities in your application. The tests confirm that each part operates correctly. First, the testApplication function initiates the tests. Here are the key components:
testApplication function runs comprehensive tests.calculateTotals checks if income and expenses are accurate.validateInput ensures that user inputs are valid and meet criteria.displayExpenses presents the list of expenses for the user to review.Your task is to create a function that tests the delete feature of the expense tracker. This function should remove an expense and confirm it was deleted successfully. Testing this feature is critical!
function testDeleteExpense() {
// Add an expense
addExpense("Lunch", 10);
console.log('Expense added.');
// Delete the expense
deleteExpense("Lunch");
const expenses = getExpenses();
console.log('Remaining Expenses: ', expenses);
}
testDeleteExpense();
To learn more about programming with JavaScript, check out our lesson on What Is JavaScript? Examples from Everyday Websites. Testing is only one of many skills you will develop in this course.