Loading...
Hello, my name is Mrs. Jones, and I'm really pleased you decided to join this lesson today.
In this lesson, we will look at testing and refining stages of a programming project, from the testing to identifying and fixing any errors in the programme code.
So let's get started.
Welcome to today's lesson.
Today's lesson is called "Testing and Refining a Programming Project" from the unit, "Python Programming Project".
And by the end of this lesson, you'll be able to test a programming project using a range of methods.
There are two key words to today's lesson: Testing.
Testing is the systematic process of checking that a programme works as expected.
Debugging.
Debugging is the process of finding and correcting errors in programme code.
There are two sections to today's lesson.
The first is perform testing.
The second is identify and fix errors in a programme.
So let's start with perform testing.
Lucas asks, "Why do we test programmes?" Good question.
Testing helps you find and fix errors before users experience problems. It ensures the programme works as expected with different inputs.
Testing helps improve reliability and user experience.
Before a piece of software can be used, it needs to be tested.
Some testing is done by the programmer as the code is written.
Other testing is more structured and involves a test table being written and the software being tested with a variety of types of data to check that the outputs are as expected.
When a problem with the software is identified, the cause will need to be identified, and this is called debugging.
The test table is a way to thoroughly check that a programme is working correctly.
It will usually specify: a unique identifier for each test.
You can see that in the first column, which is the test number.
A description of each test.
In the second column there.
The test data that is to be used for each test.
In the input section there.
A description of the expected results of each test.
And that's the fourth column.
The other two are completed as you do the testing.
The tests should include a range of test data.
Normal is this type of data should be accepted by the programme and is valid.
Erroneous: this type of data should not be accepted by the programme because doing so would cause an error.
Boundary: these are values that are on the edge of being valid.
You should check that values are at the boundary of valid.
Let's have a quick check.
True or false? Testing helps to find and fix errors before users experience problems. Pause the video to consider if that is true or false, and then we'll check your answers.
Let's check your answer.
The answer was true because testing is a crucial step in the development process that helps ensure a programme works as expected and is reliable before it is released to users.
Well done if you got that correct.
Let's do another test.
If a programme is designed to accept an age between 18 and 65, which category would the number 45 fall into? Is it A, erroneous, B, normal, or C, boundary? Pause the video to consider your answer and then we'll check it.
Let's check your answer.
The answer was B, normal, because it is a value between 18 and 65.
Well done if you got that correct.
Let's do another check.
If a programme is designed to accept an age between 18 and 65, which category would the number 18 fall into? Is it A, erroneous, B, normal, or C, boundary? Pause the video to consider your answer and then we'll check it.
Let's check your answer.
The answer was boundary, because 18 is right at the edge of that test area.
Well done if you got that correct.
This is the start of a test plan for the StreamScheduler project.
And you can see here three tests have been added.
And there is a note.
Your test plan, which you may have created in a previous lesson, should include more tests than this sample.
So these tests had: The first test was to test whether the user can input the total duration of the stream in minutes.
So the input was 22 and the expected output was that it was accepted and stored.
The second test was that the user cannot enter a value less than 20 or more than 40 for the stream duration.
So the input was 10 and the expected outcome was an error to display the message "Please enter a stream between 20 and 40 minutes." And the third test was that the total duration is converted correctly to seconds.
So the input was 22 and the expected output was 22 multiplied by 60, which gave the output of 1,320.
Let's do the activity.
Open the StreamScheduler programme that you have created previously.
Note: if you do not have a previous version, you can access one at the link given here.
Carry out these four tests and record the results.
So you have those three that we've just gone through.
And the fourth one is: The user enters various inputs.
So the input here is: The user enters 20 as the stream_minutes.
The user enters catch-the-ball as the game_name and 600 seconds as the review_duration.
The user enters collect-tokens as the game_name and 500 seconds as the review_duration.
And the user enters dodge-the-monsters as the game_name and 600 seconds as the review_duration.
The expected output is that an error to occur because the user enters 600 seconds as the review_duration for step four, which is more than the stream_seconds remaining.
And the third part is carry out any remaining tests that you may have included on your test plan.
Pause the video, use your programme and the test table, and complete your test plan, and then we'll go through the answers.
Let's check your answers.
So the first three tests were: The first one: accepted and stored, so no action was required, so it's not required.
The second, the output was "Please enter a stream between 20 and 40 minutes", so no action was required in the last column.
The third, accepted and the calculation was correct, so no action.
The fourth test, however, actual output was, it was accepted with no error.
The programme allows the user to enter review duration that makes the stream too long.
So in the final column, if the test was unsuccessful, how is it fixed? A while loop has been added to check whether the review_duration entered is valid and does not make total_time more than stream_seconds.
Well done if you identified the error and how to fix it.
Let's move to the second part of today's lesson: Identify and fix errors in a programme.
Testing allows you to identify errors in a programme.
Debugging means finding and fixing errors in code that stop it from working correctly.
An errors might be syntax errors, logic errors, or runtime errors.
Syntax errors: These are errors that occur when you have not followed the rules of the language and they will be flagged by the translator.
A programme with syntax errors will not run.
Most IDEs, integrated development environments, highlight syntax errors when you try to run your code.
Logic errors: These are errors that cause a programme to work incorrectly or unexpectedly.
With a logic error, the programme can be run without failing, but it does not return the expected result.
Logic errors are typically more difficult to detect and find than syntax errors, as the IDE will not be able to pick up the issues to produce clear error messages.
Runtime errors: These errors occur when the programme is run, as the name suggests.
They occur when the code is valid according to rules of syntax, and is also logically correct, but the environment that the programme is being run in or the input provided causes an error to occur.
To debug a programme during development, follow these steps: 1.
Find the error.
2.
Read the error message.
3.
Trace through the code to detect where the error occurs.
4.
Fix the error and run the code to check that the update works.
Let's have a quick check.
What is the purpose of debugging? Is it A, to make a programme run faster, B, to find and fix errors that stop a programme from working correctly, or C, to add new features to a programme? Pause the video to consider your answer and then we'll check it.
Let's check your answer.
The answer was B, to find and fix errors that stop a programme from working correctly.
Well done if you got that correct.
Can you spot the four errors in this programme? Pause the video, look through the code, and identify where four errors have occurred, and then I'll go through the answers.
Let's have a look at the answers: So the first error was on line four, where it's missing a colon at the end.
The second error was at the end of line five, where it's missing a bracket.
The third error is at the end of line seven, where it's missing a colon.
And the fourth error is on line nine, where it has if and it should have been elif.
At the end of the selection statements and missing the bracket, so missing the colon and the brackets will stop the programme from running.
The if on line nine should be an elif.
Well done if you got those errors.
When you completed the test table during the first part of this lesson, you identified an error.
This error occurs when a user enters a review_duration that is greater than the length of the stream.
Look at this example output: The user enters 20 as the stream_minutes.
You can see that highlighted there on the left.
This is converted to stream_seconds as 1200.
The user enters catch-the-ball as the game_name and 600 seconds as the review_duration.
There is 600 seconds left.
The user enters collect-tokens as the game_name and 500 seconds as the review_duration.
There is 100 seconds left.
The user enters dodge-the-monsters as the game_name and 600 seconds as the review_duration.
The programme allows the user to enter 600 seconds even though this is more than the stream-seconds remaining.
This was the test table.
You can see there that we actually identified this on the actual output and what needs to be fixed.
You identified that a while loop has been needs to be added to check whether the review_duration entered is valid and does not make total_time more than stream_seconds.
But we have not done that yet.
We identified the fix, but we've not completed that fix yet.
Let's do the activity.
If your programme allows a user to enter a review_duration that exceeds the total stream_length, correct this error.
Correct any other errors that you have discovered during the testing stage and record them in your test table.
Pause the video, go through your test table, use your programme, and correct your errors, and then we'll go through the answer.
Let's have a look at the solution.
So you can see here now, at the top we have: while total_time < stream seconds:, and then indented inside there is all the other code.
So it allows it to check whether the total_time is less than stream_seconds before allowing the user to add another game review.
Well done if you corrected yours, and do pause the video at this stage to look at the code in more detail to check your code against and review.
In summary: Testing is the process of checking that a programme works correctly, meets all its requirements, and handles various inputs safely.
To test a programme thoroughly, a range of data should be used, including normal, boundary, and invalid data.
A good test plan includes clear tests with predicted outcomes.
If the actual results don't match the expected results, the programme is checked for errors in a process called debugging.
Well done for completing this lesson: "Testing and Refining a Programming Project".