Unit testing Flashcards
What is a unit of work?
All the actions that take place between the invocation of an entry point up until a noticeable end result through one or more exit points. The entry point is the thing we trigger.
How many exit and entry points could a unit of work have?
one or more exit points, one entry points
Is the entry point something private or public?
Public
What is an exit point?
An exit point is an observable consequence of a unit of work that can be verified from outside the system. It’s how the system communicates or changes in a way that clients can observe.
What types of exit point exists?
Returned value
Change in state of some part f the system
Callout of third dependency such us logging
What are the characteristics of good test?
Easy to understand the intention
Easy to read and write
Automated
Consistent
Useful and actionable results
Run with a “push of a button”
Easy to trace erros
What does it mean that a test is consistent?
Each run gets the same result if u did not change anything
What are the characteristics of a good unit test?
Run quickly.
Full control of the code under test.
Do not call external dependencies such as network or database calls, runs in memory.
Isolated.
Linear when it makes sense.
What is the main difference between unit and integration tests?
Unit tests do not depend in configuring external dependencies such as databases or the filesystem.
Mention 3 questions of the art of unit testing checklist to ensure something is a unit test
Can I run and get results from a test I wrote two weeks or months or years ago?
Can any member of my team run and get results from tests I wrote two
months ago?
Can I run all the tests I’ve written in no more than a few minutes?
Can I run all the tests I’ve written at the push of a button?
Can I write a basic test in no more than a few minutes?
Do my tests pass when there are bugs in another team’s code?
Do my tests show the same results when run on different machines or environments?
Do my tests stop working if there’s no database, network, or deployment?
If I delete, move, or change one test, do other tests remain unaffected?
What is the consequence of not having isolation of external dependencies in a test?
Too much points of failure.
What is a regression?
is broken functionality—code that used to work. You
can also think of it as one or more units of work that once worked and now
don’t.
What three main criteria does exist to determine a good test.
Readability
Maintainability
Trust
What is a unit test?
A unit test is an automated piece of code that invokes the unit of work through an entry
point and then checks one of its exit points. A unit test is almost always written using a
unit testing framework. It can be written easily and runs quickly. It’s trustworthy,
readable, and maintainable. It is consistent as long as the production code we control has
not changed.
What does it mean the USE naming convention?
Unit of work under test
Scenario
Expected behavior