Automated Testing Flashcards
What is automated testing?
Automated testing is a series of instructions (a script) that tests your code works without having to interact with a human. There are many reasons you would want to do this, with the most important being:
• To save time
• To be able to add features or update code and check whether all of the code still works
• So that your project can scale easily
What are the six main types of automated testing?
- Unit Tests: These test isolated components, so maybe a single function or method. They are straightforward and simple.
- Smoke Tests: These test whether the code is operational (i.e. it can be run).
- Integration: This verifies that components can be used together.
- Functional: This is designed to show that a specific requirement has been met:
- Performance: Benchmarking memory or time usage.
- Acceptance: Acceptance tests are used to demonstrate that the specific elements of a contract have been fulfilled.
What is test-driven development?
We want to write ‘clean’ code. This is any code which is well structured, well written, and robust. The reason that it’s worthwhile to do it, even though it takes so much longer, is that:
• There is an Improvement in productivity (you’re not spending hours debugging).
• Reduced risk of catastrophic error because there are fewer errors overall.
• Enhanced Lifetime for source code.
We are not saying that you write all your tests before you write any code, it’s just that testing becomes part of writing the code. Before you write a new section of code, you write your tests.
What is PyTest?
This is one program which can be used for automated testing in python. It works as simply as this:
• If an exception is raised, the test fails.
• To raise exceptions more often, we use the assert command to check a condition is as we would expect it to be.
Describe ‘Mocking’.
Sometimes we may wish to perform tests which interact with external resources (websites, imports etc).
These resources can eb difficult to work with because:
• They change so often.
• They make version control difficult
• They can be slow
For these reasons, it often makes sense to make ‘mock’ data, data that looks the exact same as normal data but that you store in the program directly.
Describe ‘Patching’.
Patching is the ‘cousin of mocking’ Here we don’t just change the data that a function sees, but also its dependencies. This can include:
• Changing its imports
• Changing the functions it has available to it
This is done to make the tests quicker, and more bespoke.