testing_notes
testing_notes
Testing
Testing is about checking if your code works as expected. Think of it like checking
if a recipe you followed actually results in the dish you're expecting. In
programming, we write tests to make sure our code behaves correctly.
• End-to-end tests: Test the entire application, often simulating how a real
user interacts with it.
These are ways to simulate parts of your code or external systems (like a
database or API) while testing, so you don't always have to use the real thing.
o Example: You might have a function that calls an external API, but
during testing, you don’t want to call the real API. A stub can return
a fake result instead.
• Mock: A more advanced fake object that not only gives predefined
answers, but also keeps track of how it's used. You can check if a
function was called, how many times, and with what parameters.
• Fake: A fake object or service that has a working implementation, but it’s
simplified or in-memory (e.g., a fake database that stores data in memory
instead of a real database).
TDD is a way of writing code where you write tests before writing the actual
code. The process goes like this:
4. Refactor your code to make it cleaner, while keeping the test passing.
TDD helps you focus on writing code that meets the requirements and ensures
that your code works as expected.
• Mocks, Stubs, and Fakes help simulate parts of the code or external
systems during testing.
• TDD is a methodology where you write tests before writing the code,
helping you ensure your code meets the requirements and works
correctly.