π‘ 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
Unit Tests βοΈ
Tests are stories you tell the next generation of programmers on a project. βοΈ
They allow a developer to see exactly what an application is made of and where it started.
#UnitTest
@ProgrammingTip π»
Tests are stories you tell the next generation of programmers on a project. βοΈ
They allow a developer to see exactly what an application is made of and where it started.
#UnitTest
@ProgrammingTip π»
GenFu π€Ί
GenFu is a library you can use to generate realistic test data. β
It is composed of several property fillers that can populate commonly named properties through reflection using an internal database of values or randomly created data.
You can override any of the fillers, give GenFu hints on how to fill them. π
[ Website ] : http://genfu.io/
https://t.me/pgimg/9
γ°γ°γ°γ°γ°γ°
#Dotnet #Core #UnitTest
@ProgrammingTip
GenFu is a library you can use to generate realistic test data. β
It is composed of several property fillers that can populate commonly named properties through reflection using an internal database of values or randomly created data.
You can override any of the fillers, give GenFu hints on how to fill them. π
[ Website ] : http://genfu.io/
https://t.me/pgimg/9
γ°γ°γ°γ°γ°γ°
#Dotnet #Core #UnitTest
@ProgrammingTip
Telegram
Programming Tips Resources
What is Unit Testing & Why You Need to Lean It βοΈ
Unit testing is the practice of writing code to test your code and then run those tests in an automated fashion. β
πΉπΈπΉπΈ
Here is an example. π¨π»βπ»
Imagine you have this function somewhere in your code.
Itβs a basic calculate function that takes an input and depending on some conditions, it returns different values.
If you want to test this function manually :
1οΈβ£ You have to run your application
2οΈβ£ Perhaps you have to login
3οΈβ£ Maybe do a few clicks here
4οΈβ£ There to get to a page where this function is used.
5οΈβ£ You have to fill out a form
6οΈβ£ Submit it
7οΈβ£ Verify if this function returned the right result.
And then you have to repeat all these steps, each time using different values in your form. π€¦π»ββοΈ
πΈπΉπΈπΉ
Manual testing is expensive πΈ
As you can see, this is very time-consuming. βοΈ
This workflow to test this function may take several minutes every timeβοΈ
Now to make matters worse, this is not the only function in your application. π
In a real application, you have tens or hundreds of functions like this βοΈ
As your application grows in size and complexity, the time required to manually test all the different bits and pieces increases exponentially. β±
So, thatβs why we use Automated Testing. β»οΈ
πΊπΉπΊπΉ
https://t.me/pgimg/24
[ Full Article ] : http://bit.do/utdd
γ°γ°γ°γ°γ°γ°
#CleanCode #UnitTest #TDD
@ProgrammingTip
Unit testing is the practice of writing code to test your code and then run those tests in an automated fashion. β
πΉπΈπΉπΈ
Here is an example. π¨π»βπ»
Imagine you have this function somewhere in your code.
Itβs a basic calculate function that takes an input and depending on some conditions, it returns different values.
public float CalculateTax(int input)
{
if (x) return ...;
if (y) return ...;
return ...;
}
If you want to test this function manually :
1οΈβ£ You have to run your application
2οΈβ£ Perhaps you have to login
3οΈβ£ Maybe do a few clicks here
4οΈβ£ There to get to a page where this function is used.
5οΈβ£ You have to fill out a form
6οΈβ£ Submit it
7οΈβ£ Verify if this function returned the right result.
And then you have to repeat all these steps, each time using different values in your form. π€¦π»ββοΈ
πΈπΉπΈπΉ
Manual testing is expensive πΈ
As you can see, this is very time-consuming. βοΈ
This workflow to test this function may take several minutes every timeβοΈ
Now to make matters worse, this is not the only function in your application. π
In a real application, you have tens or hundreds of functions like this βοΈ
As your application grows in size and complexity, the time required to manually test all the different bits and pieces increases exponentially. β±
So, thatβs why we use Automated Testing. β»οΈ
πΊπΉπΊπΉ
https://t.me/pgimg/24
[ Full Article ] : http://bit.do/utdd
γ°γ°γ°γ°γ°γ°
#CleanCode #UnitTest #TDD
@ProgrammingTip
Telegram
Programming Tips Resources
Mocking objects with Moq and XUnit in .NET Core πΎ
This article explains the step by step process that needed to Moq an object in .NET Core βοΈ
Mocking objects comes in handy when unit testing data store, where a Database can be mocked so that no data is added or modified in Database while unit testing source code. β»οΈ
https://t.me/pgimg/32
[ Tutorial ] : http://bit.do/moqx
γ°γ°γ°γ°γ°γ°
#UnitTest #Mocking #XUnit #Moq
@ProgrammingTip
This article explains the step by step process that needed to Moq an object in .NET Core βοΈ
Mocking objects comes in handy when unit testing data store, where a Database can be mocked so that no data is added or modified in Database while unit testing source code. β»οΈ
https://t.me/pgimg/32
[ Tutorial ] : http://bit.do/moqx
γ°γ°γ°γ°γ°γ°
#UnitTest #Mocking #XUnit #Moq
@ProgrammingTip
Telegram
Programming Tips Resources
Write tests,
Not too many,
Mostly integration. β
A while back, Guillermo Rauch ( Creator of Socket.io ) tweeted something profound :
This is deep, albeit short, so letβs dive in. π
https://t.me/pgimg/62
[ Article ] : http://bit.do/iut
γ°γ°γ°γ°γ°γ°
#UnitTest
@ProgrammingTip
Not too many,
Mostly integration. β
A while back, Guillermo Rauch ( Creator of Socket.io ) tweeted something profound :
Write tests. Not too many. Mostly integration.π
This is deep, albeit short, so letβs dive in. π
https://t.me/pgimg/62
[ Article ] : http://bit.do/iut
γ°γ°γ°γ°γ°γ°
#UnitTest
@ProgrammingTip
Telegram
Programming Tips Resources