Question: This problem will test your ability to create an automated test using the unittest module. For this problem, make sure you download the display _
This problem will test your ability to create an automated test using the unittest module.
For this problem, make sure you download the displayutils.py function module and place it in the same directory where you create a file called LabPpy
Review the displayutil.py code. Note that it has two functions:
getusergreeting takes one parameter and returns a string that includes the name in a greeting.
sumisgreater takes three parameters. It returns True if the sum of the first two parameters is greater than the third parameter.
The LabPpy file will implement two automated tests that will test each of these functions. Do the following:
Import both the unittest and the displayutils modules.
Create a class called TestDisplayUtils. Inside the parenthesis, specify unittest.TestCase. That will indicate that the class you created is a subclass of the TestCase class inside of the unittest module.
Create two methods:
o testgetusergreeting has only one parameter, the self parameter.
This test method should call getusergreeting inside of displayutils and pass it the name Bob The return value should be assigned to the variable greeting:
greeting displayutils.getusergreetingBob
The test method should then use the assertEqual method available via the self parameter to see if greeting is equal to:
Hello Bob!
o testsumisgreater has only one parameter, the self parameter.
This test method should call the assertTrue method that is available via the self parameter. It should pass the following into that method:
displayutils.sumisgreater
This function call is nested inside the call to assertTrue.
At the end of LabPpy you need to add two lines that will enable this test to call the unittest main this Python file is directly called from Python:
if namemain:
unittest.main
Note, that there are two underscores before and after name and main on the line with the if statement.
After completing the implementation, run the file from the command line in the Terminal. You should see something similar to this sample output:
Sample output:
PS C:PycharmProjectsWakeTechLab python LabPpy
F
FAIL: testgetusergreeting mainTestDisplayUtils.testgetusergreeting
Traceback most recent call last:
File C:PycharmProjectsWakeTechLabLabPpy line in testgetusergreeting
self.assertEqualgreeting 'Hello Bob!
AssertionError: 'HelloBob! 'Hello Bob!
HelloBob!
Hello Bob!
Ran tests in s
FAILED failures
This exercise has been designed so the first of the two tests will FAIL. The test itself is valid but the code in displayutils.py has a bug. Make sure that you turn in the Python unittest file you created from these instructions that found this bug and do NOT change the tests so that the bug is not detected.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
