- Don’t aim at unit testing each method in the SUT. Unit test only the publicly available API.
- When writing unit tests, mimic the behavior of the SUT’s clients.
- Don’t test private methods. Either unit test them indirectly, using the public API, or extract them into separate classes and test those classes instead.
- Don’t hesitate to unit test internal classes as long as you follow the guidelines above
- Test data should kept and read from a file instead of string variable
Showing posts with label JUnit. Show all posts
Showing posts with label JUnit. Show all posts
Wednesday, May 30, 2018
Junit best practice
Thursday, September 28, 2017
Java code coverage tool for eclipse
Overview :
In computer science, code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite. A program with high code coverage has been more thoroughly tested and has a lower chance of containing software bugs than a program with low code coverage.
In this article we will see how we can generate code coverage report using tools in eclipse . There are number of tools for eclipse that we can use to generate code coverage report :
EclEmma :
In computer science, code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite. A program with high code coverage has been more thoroughly tested and has a lower chance of containing software bugs than a program with low code coverage.
In this article we will see how we can generate code coverage report using tools in eclipse . There are number of tools for eclipse that we can use to generate code coverage report :
EclEmma :
EclEmma is a free Java code coverage tool for Eclipse, available under the Eclipse Public License. It brings code coverage analysis directly into the Eclipse workbench:
- Fast develop/test cycle: Launches from within the workbench like JUnit test runs can directly be analyzed for code coverage.
- Rich coverage analysis: Coverage results are immediately summarized and highlighted in the Java source code editors.
- Non-invasive: EclEmma does not require modifying your projects or performing any other setup.
How to install EclEmma :
There are number of ways we can install EclEmma to eclipse but in this article we will see how to install EclEmma using update site. The steps are very easy :
use the following update site url in the ellipse install dialog
http://update.eclemma.org/ and follow the instruction
Help >> Install New Software
After successfully installing the EclEmma eclipse plugin ; now it is time to see the coverage report:
Right client on project and click Coverage As > JUnit Test
Running the above command execute all the JUnit test cases and generate Code Coverage report in the coverage view:
if you cannot see the find it from Window >> Show View >> Other..
Export the Report to local disk :
You can export the coverage report for later use:
Click the index.html from the exported files, your will see a coverage report like blow :
Now you can dig down you report!
Subscribe to:
Posts (Atom)
5 Strategies for Getting More Work Done in Less Time
Summary. You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...

-
Sometimes just to get a quick success build you might need to disable/ignore/skip some of the munit test cases. you can do you by double ...
-
Some times you might need to return static response from nginx. for example validating file upload limit error_page 413 @413_x...
-
Install ActiveMQ Step 1: Download Apache Active MQ 5.x.x (5.15.8 Latest Version Up to Feb 2019) Step 2: Install ActiveMQ Run the Active...