π‘ Consider the following three laws before writing Unit Test :
1- You may not write production code until you have written a failing unit test.
2- You may not write more of a unit test than is sufficient to fail, and not com-piling is failing.
3- You may not write more production code than is sufficient to pass the currently failing test.
#CleanCode #UnitTest #TDD
1- You may not write production code until you have written a failing unit test.
2- You may not write more of a unit test than is sufficient to fail, and not com-piling is failing.
3- You may not write more production code than is sufficient to pass the currently failing test.
#CleanCode #UnitTest #TDD
Test code is just as important as production codeβοΈ
It is not a second-class citizen .
It requires thought, design, and care .
It must be kept as clean as production code .
#CleanCode #UnitTest
It is not a second-class citizen .
It requires thought, design, and care .
It must be kept as clean as production code .
#CleanCode #UnitTest
What makes a clean testβ
Three things : Readability, readability, and readability.
Read-ability is perhaps even more important in unit tests than it is in production code .
What makes tests readable β
The same thing that makes all code readable :
clarity, simplicity & density of expression .
#CleanCode #UnitTest
Three things : Readability, readability, and readability.
Read-ability is perhaps even more important in unit tests than it is in production code .
What makes tests readable β
The same thing that makes all code readable :
clarity, simplicity & density of expression .
#CleanCode #UnitTest
What is Unit Test β
A unit test is a piece of a code (usually a method) that invokes another piece of code and checks the correctness of some assumptions afterward. β
If the assumptions turn out to be wrong, the unit test has failed. β
A unit is a method or function.
#UnitTest
@ProgrammingTip
A unit test is a piece of a code (usually a method) that invokes another piece of code and checks the correctness of some assumptions afterward. β
If the assumptions turn out to be wrong, the unit test has failed. β
A unit is a method or function.
#UnitTest
@ProgrammingTip
Properties of a good unit test β
A unit test should have the following properties :
1οΈβ£ It should be automated and repeatable.
2οΈβ£ It should be easy to implement.
3οΈβ£ It should be relevant tomorrow.
4οΈβ£ Anyone should be able to run it at the push of a button.
5οΈβ£ It should run quickly.
6οΈβ£ It should be consistent in its results.
7οΈβ£ It should have full control of the unit under test.
8οΈβ£ It should be fully isolated (runs independently of other tests).
9οΈβ£ When it fails, it should be easy to detect what was expected and determine how to pinpoint the problem.
#UnitTest #Tips
@ProgrammingTip
A unit test should have the following properties :
1οΈβ£ It should be automated and repeatable.
2οΈβ£ It should be easy to implement.
3οΈβ£ It should be relevant tomorrow.
4οΈβ£ Anyone should be able to run it at the push of a button.
5οΈβ£ It should run quickly.
6οΈβ£ It should be consistent in its results.
7οΈβ£ It should have full control of the unit under test.
8οΈβ£ It should be fully isolated (runs independently of other tests).
9οΈβ£ When it fails, it should be easy to detect what was expected and determine how to pinpoint the problem.
#UnitTest #Tips
@ProgrammingTip
Why use isolation frameworksβ
An isolation framework is a set of programmable APIs that makes creating fake objects much simpler, faster, and shorter than hand-coding them. π¨
#UnitTest #Mock
@ProgrammingTip
An isolation framework is a set of programmable APIs that makes creating fake objects much simpler, faster, and shorter than hand-coding them. π¨
#UnitTest #Mock
@ProgrammingTip
The Safe Green Zone β
Locate your integration and unit tests in separate places.
By doing that, you give the developers on your team a safe green test area that contains only unit tests, where they know that they can get the latest code version.
They can run all tests in that namespace or folder, and the tests should all be green.
If some tests in the safe green zone donβt pass β ,
thereβs a real problem, not a (false positive) configuration problem in the test.
#UnitTest
@ProgrammingTip
Locate your integration and unit tests in separate places.
By doing that, you give the developers on your team a safe green test area that contains only unit tests, where they know that they can get the latest code version.
They can run all tests in that namespace or folder, and the tests should all be green.
If some tests in the safe green zone donβt pass β ,
thereβs a real problem, not a (false positive) configuration problem in the test.
#UnitTest
@ProgrammingTip
Tests are part of source control β
The test code you write needs to reside in a source control repository, just like your real production code.π¦
In fact, you should treat your test code as thoughtfully as you treat your production code. βοΈ
It should be part of the branch for each version of the product, and it should be part of the code that developers receive automatically when they get the latest version. π
Because unit tests are so connected to the code and API, they should always stay attached to the version of the code theyβre testing.
#UnitTest
@ProgrammingTip
The test code you write needs to reside in a source control repository, just like your real production code.π¦
In fact, you should treat your test code as thoughtfully as you treat your production code. βοΈ
It should be part of the branch for each version of the product, and it should be part of the code that developers receive automatically when they get the latest version. π
Because unit tests are so connected to the code and API, they should always stay attached to the version of the code theyβre testing.
#UnitTest
@ProgrammingTip
Renaming or Refactoring Tests β»οΈ
An unreadable test is more of a problem than a solution. ππΏ
It can hinder your codeβs readability and your understanding of any problems it finds. β
If you encounter a test that has a vague or misleading name or that can be made more maintainable, change the test code. β
#UnitTest
@ProgrammingTip
An unreadable test is more of a problem than a solution. ππΏ
It can hinder your codeβs readability and your understanding of any problems it finds. β
If you encounter a test that has a vague or misleading name or that can be made more maintainable, change the test code. β
#UnitTest
@ProgrammingTip