Issue is resolved
The null pointer exception was due to Account record which was not getting inserted due to invalid Account ID field in createUser method. Due to that, as there is no partner account, the user record is not getting inserted in the test class. Found this issue by creating debug logs and going through the lines step by step.