Jacoco does not cover tests using #PrepareForTest(Class.class).
I need to use PowerMockito whenNew method, but it does not work without the PrepareForTest annotation.
Is there any workaround for this issue?
JaCoCo could work in two mods:
collecting coverage with java agent
offline instrumentation
If you'd like to collect coverage from PowerMock test then you should use offline instrumentation.
Here working example for Gradle: https://github.com/SurpSG/jacoco-offline-instrumentation
Related
I am revising a kotlin-js web browser application.
Currently tests are run through selenide and are limited as they interact entirely through the DOM and cannot call the code or inspect data.
More tests are needed, and I am thinking that an actual js framework is needed such as Qunit, mocha or jasmine etc.
The project is configured through gradle, but I have not found how to have tests run by a gradle project that simulate being run in the browser.
The overall question is, how to best deliver unit tests?
questions:
Is there a better approach than the selenid approach?
Is there a kotlin-js based test alternative that can be run from a gradle task?
What combination has been found to work, ideally without resorting to node.js in order to run a browser app. e.g instructions on using Qunit, jasmine, mocha or an other test running as a gradle task?
Alternatively (not preferred) Is there some way to call javascript code (functions etc) and access page global variables from the selenide test code?
Any answers to either question appreciated.
I have written a test case using powermock and easymock. I have sonarlint plugin associated with local sonarqube server. When i run sonarlint analysis on my test case no coverage is being shown. I know powermock disables eclemma coverage. Is this the same issue with sonarlint plugin too? Is there a way I can see unit test case coverage?
Currently i am using these tools to run my tests,code coverage and documentation:
Unit testing:
jasmine
xUnit
Code Coverage:
Istanbul
dotCover
Documentation:
Typedoc
As i'm trying to do everything modular for both frontend and backend we have multiple bower components and nuget packages where of course each components runs different type of tests and documentation.
Now what i want to do is to have a dedicated site which grabs all test results and documentation and have a dedicated site where all developers etc. can use it as a point of reference.
Is there any plugin available that can help me achieve it?
if not do you have any idea from where can i start as i tried googling a bit but with no luck.
I'm using roughly the same technologies.
As a build server I use TeamCity.
In a nutshell: your build is composed by steps, e.g (simplified):
build .sln
gulp build
xUnit tests (*A: publishing coverage)
karma run
remap coverage from Javascript to Typescript (*B: publish coverage)
The only problem I had so far is with the coverage (*A + *B). The last data will overwrite the first one, (not average it all). So in that case I use custom reports page to display the istanbul generated html report and only use the xUnit coverage report.
You could have the coverage.json from istanbul as an artifact of your build, and a second build picks up and reports that coverage through teamcity. It would be simply a coverage report build (only 1 step, report code coverage). The trigger is a successful build generating the coverage.
For your generated documentation you can also use custom reports page.
About the unit tests execution (both jasmine (karma?) and xunit), both report its numbers and the final Test report will show them combined.
I have more of a theoretical question. We have a project with complicated module hierarchy. The goal is to measure unit test coverage and in the future also integration test coverage.
In order to properly place the testing dependancies, plugins and configurations in the different project poms, I need to understand the interplay between the following plugins:
failsafe
surefire
jacoco
What I know is, failsafe generates integration test reports, surefire generates the unit tests reports and jacoco can use both to generate the test coverage report.
What I need to know is:
How jacoco interacts with both failsafe and surefire?
Do jacoco need failsafe and surefire?
Can you explain the jacoco configuration and particularly why does the problem with the argLine occur?
I found a lot of examples scattered, and got the jacoco plugin working, but my goal is to place all configs etc. where they are actually needed, so that they do not pollute the maven dependency-hierarchy.
I have recently discovered Spring project for MVC testing: spring-test-mvc. It's a great tool, and I plan to use it more in the future.
However I have noticed a problem with it on my Jenkins CI. The problem is that while MVC integration tests are passing locally, and even on Jenkins CI job, the problem occurs in the Jenkins' Sonar plugin execution. In this case all asserts done with ".andExpect()" method I tried fail. Yes, they pass if Sonar plugin is not used.
For example
this.mockMvc.perform(get("/someController/some.action").param("someParam", "someValue"))
.andExpect(status().isOk())
.andExpect(content().type(MediaType.APPLICATION_JSON))
.andExpect(request().sessionAttribute("someAttribute", notNullValue()));
In the above test content type and session attribute assertions are failing.
Any ideas? Thanks in advance.
The problem is solved by kind people from spring-mvc. More details can be found on the provided link. In short, in my case Sonar uses Cobertura for coverage testing.
Cobertura adds the interface HasBeenInstrumented and because of that
the class is decorated as a JDK dynamic proxy instead, which means a
synthetic proxy class with one interface that's not very helpful since
it's a Cobertura marker interface. As a result and the controller can
never and no annotations can be properly discovered.
The problem is solved by adding proxy-target-class="true" to <tx:annotation-driven> element
I also faced the same issue. We upgraded the Cobertura jar version to the latest. This change made the JUnit testcases to run in local as well as in Jenkins