Unit testing
What makes a good unit test and how to write them in any language: what a unit is, the arrange-act-assert structure, examples in Python with pytest and JavaScript with Vitest, test doubles (stubs, mocks and fakes), testing edge cases, designing code that is easy to test, the testing pyramid, coverage, and the habits that keep tests fast and trustworthy.
CodexBash, , 6 min read
A unit test is a small, automated check that one piece of code, a function, a class or a module, behaves as expected. Hundreds of them run in seconds, every time you change code, telling you immediately if something broke. Teams with good unit tests refactor confidently, upgrade dependencies without fear and catch bugs before users do. Teams without them move slowly and break things anyway. Our article on testing with JUnit covered Java specifics; this one covers the principles that apply in every language, with examples in Python and JavaScript.
Sign in to read the rest
The whole 6 minute article is free with an account, along with every problem, lesson and tutorial. No card.