EclEmma Coverage checking using Eclipse - junit

I want to check my test coverage of GWT codes using EclEmma, when i run coverage it always shows zero percentage of coverage in report.
Can any one help me out..
Below is the image of coverage report, it show i didn't cover any instructions,
thanks anyway..

Are you using PowerMock?
See this issue.

Ensure the EclEmma global filters are correct.
On Preferences, Java, Code Coverage it should show Includes: * and nothing in Excludes:

Related

Changes of Code Coverage in SonarQube 6.2

I have a problem: I used to use SonarQube version 5.1 where I had JUnit and Integration tests' code coverage set up. Both of these were represented by three items in SonarQube (coverage, it_coverage, overall_coverage - the previous two merged).
Since the 6.2 version, the coverage and it_coverage shouldn't be available anymore, there is supposed to have just an item called coverage which is the value of the item overall_coverage of previous versions (if report paths to jaccoco are set up correctly for jUnit reports and integration tests reports), everything should work well.
My question is, how can I recognize that the integration tests are included in the coverage cause, I don't have any indicator which makes me know that these tests were part of the analysis, cause I still see just the number of unit tests where the Jameleon ones are not listed in.
There is no visual way in SonarQube to be sure that your IT coverage has been taken into account.
You can probably look at the analysis logs to verify that the reports are found (if not, you will get a warning message).
If you want to be sure, you can also run an analysis without specifying the IT report and see if there's a difference or not.

How to take screenshot on test failure with junit 5

Can someone tell me please: how to take a screenshot when test method fails (jUnit 5). I have a base test class with BeforeEach and AfterEach methods. Any other classes with #Test methods extends base class.
Well, it is possible to write java code that takes screenshots, see here for example.
But I am very much wondering about the real problem you are trying to solve this way. I am not sure if you figured that yet, but the main intention of JUnit is to provide you a framework that runs your tests in various environments.
Of course it is nice that you can run JUnit within your IDE, and maybe you would find it helpful to get a screenshot. But: "normally" unit tests also run during nightly builds and such - in environments where "taking a screenshot" might not make any sense!
Beyond that: screenshorts are an extremely ineffective way of collecting information! When you have a fail, you should be locking for textual log files, html/xml reports, whatever. You want that failing tests generate information that can be easily digested.
So, the real answer here is: step back from what you are doing right now, and re-consider non-screenshot solutions to the problem you actually want to solve!
You don't need to take screen shots for JUnit test failes/passes, rather the recommended way is to generate various reports (Tests Passed/Failed Report, Code coverage Report, Code complexity Report etc..) automatically using the below tools/plugins.
You can use Cobertura maven plugin or Sonarqube code quality tool so that these will automatically generate the reports for you.
You can look here for Cobertura-maven-plugin and here for Sonarqube for more details.
You need to integrate these tools with your CI (Continuous Integration) environments and ensure that if the code is NOT passing certain quality (in terms of tests coverage, code complexity, etc..) then the project build (war/ear) should fail automatically.

Coverage report of multi module project

I am having a issue with generating code coverage report and getting an analysis of unit tests covering the project code. I have used Sonar to get a report on project but the unit test coverage section do not show anything. I have done some research and found that sonar needs to have a junit report generated by emma/clover/corbetura/jacoco. The project is non-maven based. Please tell me how can I analyse code coverage for a non-maven based multi-module project. I am using sonar runner.
Any link or reference will be helpful.
Please do not give links of documentation pages. Apparently, I have browsed them all.
Thanks in advance.
I'm giving the links to the documentation pages to help others who have not seen the documentation or examples. Take the maven property settings and translate them into sonar-runner.properties. For example, depending on how you set up your multi-module project you might put this setting in the parent level or inside each module: sonar.jacoco.reportPath=reports/coverage/jacoco.exec
Here is the link to the multi-module sonar runner project:
http://docs.codehaus.org/display/SONAR/Analyzing+with+SonarQube+Runner
To configure unit test code coverage apply the same properties in maven to the sonar-project.properties file. Here is the example from the Code Coverage example:
https://github.com/SonarSource/sonar-examples/tree/master/projects/code-coverage
Note you need to set the unit and coverage properties as well as the source encoding properties.
sonar.projectKey=org.codehaus.sonar:example-ut-sonarRunner-jacoco-reuseReports
sonar.projectName=UT coverage with SonarQube Runner reusing JUnit and JaCoCo reports
sonar.projectVersion=1.0
sonar.sources=src
sonar.binaries=classes
sonar.language=java
# Tells SonarQube to reuse existing reports for unit tests execution and coverage reports
sonar.dynamicAnalysis=reuseReports
# Tells SonarQube where the unit tests execution reports are
sonar.junit.reportsPath=reports/junit
# Tells SonarQube that the code coverage tool by unit tests is JaCoCo
sonar.java.coveragePlugin=jacoco
# Tells SonarQube where the unit tests code coverage report is
sonar.jacoco.reportPath=reports/coverage/jacoco.exec
# Encoding of the source files
sonar.sourceEncoding=UTF-8

jUnit: How to determine level of code coverage?

How can i determine what percentage of my methods (and code) are covered by jUnit tests? I am assuming there is a more sophisticated way then simply counting ... and 1 and 2 and ..
I specifically wonder how will such counting be handled when single method is covered by 'n' tests.
I've used EclEmma very successfully to cover JUnit test runs. And its free.
This presentation points to several tools you can use for the purpose.
Cenqua Clover $250-$2500 payware http://www.cenqua.com/clover/
Cobertura (GPL): http://cobertura.sourceforge.net/
Coverlipse Eclipse plug-in:
http://coverlipse.sourceforge.net/index.php
Jester: http://jester.sourceforge.net/
I would suggest to go for Cobertura for code coverage. It gives detailed information and can give you line by line coverage as well as branch coverage.

How to find functions which are not executed?

I have a MS Visual Studio 2005 workspace, all C code. I want to find all the functions in that code, which are not called/executed when a certain test case is executed.
What is the way to get that using
1.) MS VS 2005 itself or MSVC6.0 ?
2.) Using some other tool?
-AD
Might want to look into the code coverage tool in VS 2005 Team Edition. There's an FAQ on it here
There's another tool out there called ncover that looks like it does something similar as well. Seem's pretty expensive, but they do have a 30 day trial.
I'm sure others will chime in with other tools that might fit the bill as well.
Assuming your test case is in a VS2005 test project, you should be able to use the 'code coverage' feature.
On the menu choose Test->Edit Test Run Configuration ()
From here select CodeCoverage tab to the left, then check the DLLs or EXEs that contain the code you wish profiled.
Next run your test, and on completion, you should be able to select Test->Windows->Code Coverage
This gives you some metrics on the coverage such as lines executed, and you call also double click entries, to jump in to a file and have onscreen highlighting of the code that was or was note executed
Use a code profiler. Any good code profiler should include coverage tools to give you an idea of what was called and what was not called.