Where should a beginner start when writing tests?
For further actions, you may consider blocking this person and/or reporting abuse
Where should a beginner start when writing tests?
For further actions, you may consider blocking this person and/or reporting abuse
Nozibul Islam -
Arsalan Mlaik -
Jack Pritom Soren -
Vikas76 -
Top comments (6)
Some general tips that I see a lot of developers miss:
"Test Behavior, Not Implementation" - my tip is to write this down on a post-it note and stick it on somewhere.
Don't overthink "what to test". It will come naturally once you get the hang of it.
Start from the outside in with integration testing, at least when using a framework like Laravel or Adonis.js, they make this super easy.
Focus on the user flows for your application. If it's a web app, that's your web app visitors. If it's a command line interface you develop, it's the users of that CLI.
For anything web based, look at cypress.io. To start, there's no need to fully automate end-to-end tests for each pull request - that's something to work on later. Start with running your test suite against a staging or even production environment ever hour or 30 minutes, depending on how often you deploy. Then try to automate that process so that the tests run automatically after each deployment.
Write unit tests for complex functions. Don't test get and set functions on classes. A solid, fast-running test suite of end-to-end tests is more valuable in my opinion than 100% unit test coverage with lots of mocked parts of the overall system.
I would say start simple, create tests for the simple things that make sense and then slowly expand over time to more complicated testing.
Diving in too fast and trying to achieve too much too soon will probably leave you wondering 'why bother with tests' until you realize that as a program grows, tests help keep everything straight.