-
Notifications
You must be signed in to change notification settings - Fork 0
Home
##Junit Testing
#####What :
-
JUnit is a unit testing framework for the Java programming language.
-
JUnit has been important in the development of test-driven development
-
One of a family of unit testing frameworks
-
[Site Reference][id1] [id1]:https://github.com/koolApi/Junit/wiki/Site-Reference
#####Guidelines For Writing Test Cases :
######What is a Test Case? Methods are written to execute a partical functionality. So test cases are list of actions, written to test that particular functionality.
- Test only one code unit at a time
- Mock out all external services and state
- Don’t unit-test configuration settings
- Write tests for methods that have the fewest dependencies first, and work your way up
- All methods, regardless of visibility, should have appropriate unit tests
- Use the most appropriate assertion methods
- In your build script, ensure that test code is not deployed with actual source code. Its a wastage of resource.
- Do not print anything out in unit tests
- Do not use static members in a test class. If you have used then re-initialize for each test case
We already have stated that each test case should be independent of each other, so there shall never be a need to have static data members. But, if you need any for critical situation, then remember to re-initialize to its initial value before executing each test case.
- Do not write your own catch blocks that exist only to fail a test
If any method in test code throws some exception then do not write a catch block only to catch the exception and fail the test case. Instead, use throws Exception statement in test case declaration itself. I will recommend to use Exception class and do not use specific subclasses of Exception. This will increase the test coverage also.