Automated Testing Flashcards

1
Q

What is automated testing?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the six main types of automated testing?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is test-driven development?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is PyTest?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe ‘Mocking’.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe ‘Patching’.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly