CyberPunkMetalHead / gateio-crypto-trading-bot-binance-announcements-new-coins

This is a crypto trading bot that scans the Binance Annoucements page for new coins, and places trades on Gateio
MIT License
1.21k stars 303 forks source link

Refactoring code to improve Unit Testing #117

Open Linus045 opened 2 years ago

Linus045 commented 2 years ago

To add better unit testing, code needs to be refactored. Otherwise it will be nearly impossible to test individual modules/functions.

The way I see it is to start with the simple stuff like the logging module and then try to untangle the main method and split it into seperate modules/methods which can be easily tested. This will allow us to implement GitHub actions to run the tests automatically. I started to refactor the logging module in #103 and would try to get some basic testing done for that first and once everything works correctly move on to bigger functions.

I personally haven't done much unit testing in python so help and improvements/ideas are really appreciated :) The idea of this Issue is to discuss possible ideas to structure the codebase to make it possible to implement unit testing.

Linus045 commented 2 years ago

I implemented a possible version of this on my own fork on the develop branch see here: https://github.com/Linus045/gateio-crypto-trading-bot-binance-announcements-new-coins/blob/develop/tests/test_new_listings_scraper.py

I'm using pytest-mock and requests-mock to simulate the possible requests/unrelated function calls.

This could be expanded somehow to simulate a coin release and test if the bought correctly detects it and tries to buy the coin.