Programming Tips πŸ’‘
51.7K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips πŸ’‘
Articles πŸ“•
Resources πŸ‘Ύ
Design Patterns πŸ’Ž
Software Principles βœ…

πŸ‡³πŸ‡± Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
πŸ’‘ 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
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
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
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
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
The Art of Unit Testing in C#.pdf
13.8 MB
The Art Of Unit Testing in C# πŸ“˜
Author : Roy Osherove πŸ–Š

#Book #UnitTest
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
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
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
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