DEV Community

zoharasulin
zoharasulin

Posted on

osdc-assigment11-unittest

In last session we learned about Unit test on process and function code we build.

Unit testing is a critical aspect of software development as it helps identify and fix bugs early in the development process. By writing unit tests, we can verify the behavior and functionality of individual units of code, such as functions or methods, in isolation.

we over on many important examples and syntax code in presentation :

  1. Testing Demo
  2. Testing with PyTest

I chose to do a unit test on a repo that I had already built CI on
But because it's just an API
There was meaningful to build a test on.
So I chose code that this API is based on from another repo.
My repo that i build on PR is university-domains-list
One example of my test- Testing with Multiple Country Scopes:

def test_multiple_country_scopes(self):
    source_data = [...]  # Sample source data
    filtered_output = country_filter(source_data, ["China", "France"])
    expected_output = [...]  # Expected filtered output for China and France
    self.assertEqual(filtered_output, expected_output)
Enter fullscreen mode Exit fullscreen mode

my PR that I send to author:

HI .
This PR was sent as part of course OSDC taught by: @szabgab.
I add file test to your code filter.py.
I think this tests can help your project when in further- you change the code or maybe add more features.
I see your project and project API that base on your code and it very intersting.
I wonder that was in your list json universities and colleges from Israel(my country :))
Nice job!

Conclusion
In this unit test, I have explored the process of writing unit tests for Project university-domains-list country_filter function. I have covered different scenarios, including single country scopes, multiple country scopes, non-existent country scopes, empty source data, and empty country scopes. By writing these tests, I can ensure the correctness and robustness of the function, catching any potential bugs or issues early on.

Unit testing is an essential practice in software development, enabling us to build reliable and maintainable code. By investing time and effort into writing comprehensive unit tests, we can increase confidence in our codebase and streamline the development process.

I hope I have convinced you why you should test your next project
A little secret - it's very easy but much more important.

Hope to hear soon
Zohar.

Top comments (0)