Explain what are black box and white box testing

Assignment Help Python Programming
Reference no: EM133087568

Lab - Testing, Error Handling and Debugging

Exercises

Question 1. In your own words, explain what black box testing and white box testing are - including the major difference between them.

Question 2. When Unit Testing our code, we use a combination of Test Cases and Unit Tests. Describe what each of these three terms mean, including the difference between test cases and unit tests.

Question 3. You are provided with the following Python code for a function that adds two numbers. Copy and paste the code into a .py document, import the unittestmodule, and then write a test case consisting of two unit tests that pass and two unit tests that fail.

defsum_values(first, second):
"""Calculate the sum of two values and return the result."""
the_sum = first + second
return the_sum

Once you have your passing and failing unit tests and have run them, modify the function so that all the unit tests pass! There may be a variety of ways to do this which will depend on details of the failing unit tests that you wrote - for example, there may be too many or too few parameters provided, or the data types might not match etc. Fix the code so that it passes your unit tests as you see fit.

Question 4. A check digit is a single digit in a larger value that is used to determine whether the value as a whole has not been modified or corrupted and is valid. Lots of things have check digits embedded in them to ensure the number provided is legal - for example bar codes on products, credit card numbers, tracking numbers on parcels etc.

You are provided with a class called UniversalProductCode which calculates the check digit of a value using the following process:
a) Add the digits in the odd-numbered positions (first, third, fifth, etc.) together and multiply by three.
b) Add the digits (up to but not including the check digit) in the even-numbered positions (second, fourth, sixth, etc.) to the result.
c) Take the remainder of the result divided by 10 (modulo operation) and if not 0, subtract this from 10 to derive the check digit
The code for the class is provided below (either copy and paste it into a file called upc.py or download a version from the Moodle shell for this weeks' lab):

Now that we have a class to test, create a upc_test.py file in which you should write a TestUniversalProductCode class that uses Python's unit test module to test that various product codes are valid or invalid, and that providing data in the wrong format (i.e. a product code that contains letters is not valid). Take a look at slides 24 to 30 of this weeks' lecture to help get you started.

You can look up some valid universal product codes (for example, here's some for Cadbury chocolate bars - but you can search for anything: add a zero at the beginning if valid codes looked up say they are not valid!).

In your TestUniversalProductCode class you should write a test that checks for a few different valid and invalid UPC codes, and modify the UniversalProductCode class to raise an exception instead of crashing when provided with illegal data (i.e. ‘OneTwoThree' is illegal because it doesn't contain only digits).
Use the unittestsetUp(self)method to provide a number of UPC codes in a list (see slide 32 for details on how to use the setUp method, and slides 34 onwards for details on exception handling).
For the above three UPCs, you should use the assertTrue, assertFalseand assertRaisesassertions to ensure the first (valid) code is accepted as valid, the second isn't, and the third throws an exception.

Question 5. In your own words, explain why you should use logging to help debug your programs instead of using the print statement?
Also, write a small program that uses Python's logging module to log five different log messages, each with different levels of importance (debug, info, warning, error, critical).

Question 6. Our final activity for today will be to experiment with the Python debugger, which is called pdb.

Next, click the "Clone or download" button and then select "Download ZIP". Save the pdb-tutorial.zip file to the desktop and extract it.

Attachment:- Error Handling and Debugging.rar

Reference no: EM133087568

Questions Cloud

Diversity and equity : Write a post evaluating these proposed ethical news values for their usefulness. Could these new news values really be followed in journalism?
Concept of victim impact statements : Discuss the concept of victim impact statements and the impact that they have on victims, as well as, the defendant.
Crime victims : What rights does the state that you reside in provide to crime victims? What rights do you believe to be the most important?
What consideration would you bring to legal process : What consideration would you bring to the legal process (Miranda Rights)? Is there a specific way to conduct the interview,
Explain what are black box and white box testing : Describe what each of these three terms mean, including the difference between test cases and unit tests and Calculate the sum of two values and return
Law enforcement officer used physical force : Describe one example from real-life news within the past three years to illustrate a time when a law enforcement officer used physical force
Safe policing for safe communities : Also research the Executive Action implemented by President Trump before he left office in June 2020. It is titled Safe Policing for Safe Communities.
Historical and current status of police community relations : What is historical and current status of police community relations (particularly concerns minorities) and what are some underlying reasons for that situation.
Emergence of concept of community-oriented-policing : Using CSU library resources look for literature on the emergence of the concept of Community-Oriented-Policing.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd