w3resource

Python Unit Test: Exercises, Solutions, and Practice

Python Unit test [ 10 exercises with solution ]

[An editor is available at the bottom of the page to write and execute the scripts.   Go to the editor]

The unittest unit testing framework was originally inspired by JUnit and has a similar flavor as major unit testing frameworks in other languages. It supports test automation, sharing of setup and shutdown code for tests, aggregation of tests into collections, and independence of the tests from the reporting framework.

1. Write a Python unit test program to check if a given number is prime or not.
Click me to see the sample solution

2. Write a Python unit test program to check if a list is sorted in ascending order.
Click me to see the sample solution

3. Write a Python unit test program that checks if two lists are equal.
Click me to see the sample solution

4. Write a Python unit test program to check if a string is a palindrome.
Click me to see the sample solution

5. Write a Python unit test program to check if a file exists in a specified directory.
Click me to see the sample solution

6. Write a Python unit test that checks if a function handles floating-point calculations accurately.
Click me to see the sample solution

7. Write a Python unit test program to check if a function handles multi-threading correctly.
Click me to see the sample solution

8. Write a Python unit test program to check if a database connection is successful.
Click me to see the sample solution

9. Write a Python unit test program to check if a database query returns the expected results.
Click me to see the sample solution

10. Write a Python unit test program to check if a function correctly parses and validates input data.
Click me to see the sample solution

Python Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Test your Python skills with w3resource's quiz



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/unittest/index.php