I'd recommend you to separate view (web part) and business logic, so business logic sits in a separate class (with namespace) and web part is responsible for gathering data from view and passing it to the appropriate class. In such scenario you'll need to test a class that processes data not a web part.