Understanding Distributed Systems Flashcards
Pros of tests?
- working of current feature
- checking if current changes break existing features
- well written tests are great documentation
- by using TDD you force clean code on codebase
How TDD helps with writing clean code?
- firstly you focus on writing requirements, so tests are more functional and code has more business methods than code methods.
- To easily write tests, classes needs to be shor, well divided and often written to interfaces.
- code coverage 100% facilitates refactor
Parts of TDD?
Write failing test -> test passes -> refactor
What is SUT?
System under tests (scope of the test)
Types of tests
- unit
- integration: top-down, bottom-up, hybrid, contract tests
- end-to-end: user journey
- Nonfunctional tests like security tests, load tests, performance tests
What unit tests should check?
Public API and state of SUT, which is a class.
What is user-journey test?
It tests the whole scenario - like process of selecting an item and buying it. Exactly like user.
Pros:
- better testing most valuable functionality of app
- despite it’s big tests, quicker to write and maintain DJ test instead multiply EE tests for each step.
What contract tests check?
It defines request and response of the dependency. It is used in integration tests to simulate it AND in the dependency test suite. Thanks to this, we are sure that responses are closest to real one.
What is testing double?
This is prod code dependency which in tests needs to be somehow simulated.
Type of test doubles
- fake
- stub
- mock
What is fake in the testing scope?
lightweight implementation of a dependency, like in-memory db instead of real db.
What is stub in the testing scope?
test double which just returns things - no way to check how system interacts with it during test.
What is mock in the testing scope?
smarter stub - we can check how system interacts with it and still simulate return value.
Fake vs stub vs mock?
Usually fake > mock > stub (especially when fakes are written by an author of real dependency)
What is continuous integration?
Process of merging changes in code done by developers to master branch with additional automatic checks like “static analysis”, unit tests run on server