how do I get better at unit testing? Tips form y’all?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people's questions, and connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Being able to properly unit test your code also requires that you can break it down into sensible modules that can be either mocked or tested, each in total isolation from one another.
Your code should be designed in a way that allows you to feed it data and not care where the input/output comes from/goes to. So the actual reading and writing to the file is abstracted away and your core code should be outputting some sort of sensible data structure, that then gets translated to the file format you need. You should be able to test your core logic and file reading/writing completely separately.
Unit test should be small, and independent. If you need to bring up real dependencies instead of mocks, then your unit test became fragile because that real dependencies can bring changes unrelated to your expectations.