I have a script of about 50 lines that reads data from a database, loads it into a pandas dataframe and then perform numerous operations on the dataframe.
I was wondering how people generally test this type of code? I'm not talking about tools like assert_frame_equal, but rather principles people follow.
For instance, should I create 50 separate tests to basically test each operation performed or should I try to break up the script in smaller parts?
If anybody knows of quality open source projects that I can use as inspiration, please let me know.
If you want to start to write python unit test, this question is recommended.
Since the 50 lines are relevant, you probably want a functional test.
Read the difference between unit, functional, acceptance, and integration testing.
If you know SOLID principle of object-oriented-design, refactoring to the code is needed.
About how to design a good test, What are the properties of good unit tests
Specific to pandas, use fewer data to improve performance for testing.
Make a dummy copy for testing, rather than use the origin data.
And check mainly on the key feature, you want to check.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With