Testing Flashcards

1
Q

First Tests (bottom of pyramid)

A

Unit Tests: The smallest unit of testing - used to test the smallest pieces of your application in isolation to ensure each piece works before you attempt to put those pieces together. Each unit test should focus on testing one thing. These are generally the fastest tests to write and run.

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

Second Tests (middle of pyramid)

A

Integration Tests: Once you have your unit tests in place you know each piece works in isolation - but what about when those pieces interact with each other? Integration tests are the next level up, they will test the interactions between two pieces of your application. Integration tests will ensure the units you’ve written work coherently together.

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

Third Tests (top of pyramid)

A

End-to-End (E2E) Tests: End-to-end tests are the highest level of testing - these will test the whole of your application. End-to-end tests are the closest automated tests come to testing the an actual user experience of your application. These are generally the slowest tests to write and run.

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

Why TDD?

A

Writing tests before code ensures that the code written works.
Code written to pass specs is guaranteed to be testable.
Code with pre-written tests easily allows other developers to add and test new code while ensuring nothing else breaks along the way.

Only required code is written.
In the face of having to write tests for every piece of added functionality TDD can help reduce bloated un-needed functionality.
TDD and YAGNI (“you ain’t gonna need it”) go hand in hand!

TDD helps enforce code modularity.
A TDD developer is forced to think about their application in small, testable chunks - this ensures the developer will write each chunk to be modular and capable of individual testing.

Better understanding of what the code should be doing.
Writing tests for a piece of code ensures that the developer writing that code knows what the piece of code is trying to achieve.

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

TDD Workflow

A

Red: Write the tests and watch them fail (a failing test is red). It’s important to ensure the tests initially fail so that you don’t have false positives.

Green: Write the minimum amount of code to ensure the tests pass (a passing test will be green).

Refactor: Refactor the code you just wrote. Your job is not over when the tests pass! One of the most important things you do as a software developer is to ensure the code you write is easy to maintain and read.

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