What is Unit Testing?
- It’s a software testing approach.
- Testing will be done for individual unit/components of software.
- Unit is smallest part of software, which accept one or some inputs and returns an output.
- Example, A method, which accepts the two inputs length and width as input, return the area of rectangle as output. We can consider this method as a unit. This unit will be the small part of project which can be testable.
Note: Unit can be a method, procedure, program, function etc.
- It’s a base/first level of testing. This will be done before integration testing.
- Done by developer at the development stage of project.
Unit Testing Types
There are two types in unit testing,
Unit testing are commonly automated, but somewhere it done manually. As such, unit testing automation is preferred.
Commonly used Unit Testing Tools
Below are the commonly used unit testing tools, on the other hand lots of unit testing tools available.
- NUnit – used for .net applications.
- Junit – used for java applications.
- PHPUnit – used for PHP applications.
- EMMA – Java based code coverage tool.
- JMockit – automated testing toolkit for Java
Unit Testing Workflow
- Need to create new test cases
- Review and Rewrite the test cases
- Baseline – it’s a point when to end writing test cases and start the execution.
- Execute the test cases.
Advantages of Unit Testing
- Developer will understand the complete functionality of the code/unit/component, since developer covers all possible cases in writing unit testing.
- We can execute tests only for some part/modules of projects, don’t need to wait whole project or other developer gets to complete their side works.
- This allows developer can do multiple code refinement which ensure the unit works perfectly.
- To help developers to reuse the code.
- To help developers to identify the bugs at early development stage.
- Proper testing cases done in development stage saves both time and money.
Mistakes Developer makes while writing Unit Testing:
- Write minimal unit test cases.
- Concentrate on code logic and implementation only instead of unit testing.
- Intentions to complete the project quickly, this will reduce unit test cases counts.
These kinds of mistakes raise issues/defects in next level of testing, which is integration testing, system testing. So, which takes time and cost to fix issues.
What is Integration Testing?
- It’s a type of testing where all the modules in the software are integrated and tested as a group.
- Testing the user interaction/data communications between the modules.
- Integration testing will be performed to by combined all units/modules, once unit testing has been done for individual modules.
Difference Between Unit Testing and Integration Testing
|Unit Testing||Integration Testing|
|Each module tested separately.||All modules are combined and tested.|
|This is base/first level of testing.||Integration testing is performed after unit testing is done.|
|White Box testing.||Black box testing.|
|Developer will do the unit testing.||Tester will do the integration testing.|
|Defect is identified at development stage itself.||Defect is identified at testing stage.|
|Can be tested by each part, without other to be completed their parts.||Can be tested only after everyone complete their parts.|
|Less Costly.||Costly compared to unit testing.|
|Tester/Developer will know the internal design of software.||Tester/Developer doesn’t know the internal design of software.|
What is Test Driven Development (TDD)?
- This is test-first development approach.
- First write the test code, then write minimal code to pass the test, run this test code might fails due to tests codes are written even before the development code. Need to enhance and refactor the development code to pass the test.
Test Driven Development (TDD) Workflow
- Write Test Code
- Run the Test Code
- Check the failed Tests
- Make Development code to pass tests
- Repeat step b.
Advantages of TDD
- This leads developer should completely understand the requirements and think the way to write the development code before start to write actual code.
- Since tests are written first, ensure the good quality of codes, also this will improve the overall product quality.
- You can automate the tests using TDD, this will save time compared to using other manual testing process.
- Chances to raise defects will be less
- Regression testing time will be reduced.