I’m currently unit testing my project, but I’m stumped about how I should unit test JWTs from the jwt-go pkg. Should I just use one test-case that checks for any errors or handle each error as its own test-case?
Should I just use one test-case that checks for any errors or handle each error as its own test-case?
Both ways are correct. It comes down to one question: how much work are you willing to do?
Single test case for any error is simple and less painful. Handling each error as its own test-case gives you overall better coverage but introduces more complexity and can be overkill for simple project.
Each test case should ideally test one specific thing. When you have a test that checks for all errors, it becomes less clear which specific error condition led to a failure.
2 Likes
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.