A unit test is a test that designed confirms the functionality of a small unit of work in a large system i.e. check the functionality of a method of that held inside a class and ensures that the method behaves as expected.
A unit test usually tests ONE specific requirement for ONE specific method. Unit tests are fit one requirement/one method rule. If your test violates the one requirement/one method rule than that means it is some kind of test, but not a unit test.
Characteristics of Unit Test
Unit tests have following attributes that further define them as a unit test:
Unit tests that test one thing (including one set of inputs) at a time are targeted.
The code you are testing should be isolated from other code in the application as well as any external dependencies or events
• Repeatable and Predictable:
A unit test should be capable of being run over and over and assuming that the code under test and the test itself have not changed, producing the same result.
Generally speaking you have no guarantee that your unit tests are going to run in any specific order. Nor should your tests expect or require this.
Benefits of using Unit Tests
• One can focus his/her entire efforts on that code portion (that he/she is testing).
• Don’t need to know the detail of other parts of the system (unless have direct dependency on them). This makes writing the test and resulting the code easier.
• If any defect causes inside the code then the test will fail, so will be easily find out where is the defect and recftor the code to fix the defect.
Unit tests are generally done by developers. So as soon as find any defect code refactoring and fixing defect done instantly.
CSM, CSPO, CSD, CSP-SM, CSP-PO (ScrumAlliance.org)
Certification Profile Link-
Currently working as Lead Team (Application Architecture) at Raven Systems Ltd. Passion for software development especially agile practices such as TDD with in depth knowledge of Object Oriented Programming, SOLID Principles, Gang of Four Design Patterns, Some Enterprise Application Architectural Patterns. Over 8 years of software development experience ASP.NET. Has the ability to understand and transform complex business requirements into software ensuring applications are delivered on time. Also experience in non Microsoft .NET technologies such as Dapper.Net, Git, Structure Map & Angular, Bootstrap, HTML-5, CSS-3 etc.