Is there a way to show jacoco code coverage using an endpoint like /codecoverage? - jacoco

i generated code coverage using the maven jacoco plugin successfully. Now i want access the report directly with an endpoint without actually opening index.html file. is there any way to add a path to show code coverage ?

Related

Debugging API and unit test from same solution

I have a WebAPI project and a test project for API in same solution as shown below.
The code of controller is shown below. As you notice I have a breakpoint setup on the Get method
The API is working fine such as via postman or browser as shown below.
One of the unit test is just calling the same Get API via HttpClient class.
Problem is I want to setup both projects (API and test) so that I can debug code from a single solution. For that I have setup both of these projects as start up
If I hit F5 key to start debugging, I get following warning which makes sense
In order to debug the unit test and choose “Debug Tests” option as shown below
With that I get following exception that A connection with the server could not be established.
In summary
1. The API is working fine as I can test it via PostMan
2. If I move the unit test project in a separate solution, then I can debug API fine. The breakpoint get hit and everything is fine
My question is how to debug this when I have both projects in the same solution?

Unit Testing Swagger Output

We are using Swashbuckle to generate the swagger output for the REST endpoints of our MVC api application. I'm wondering what options there are for unit testing the swagger in a test project. I want to verify things like method names, descriptions, parameters etc etc to minimize the possibility that breaking changes can be introduced.
Thanks,
Please try Swagger-Codegen, which is a free an open source project to automatically generate API clients, server stubs and API documnetation.
For the C# API client generated by Swagger Codegen, it comes with test files for unit testing and you can update it to detect breaking changes by reusing the same tests after updating the OpenAPI/Swagger Spec files.

cobertura code coverage for jetty server

Hi I am trying to get code coverage for my web application.
I Instrumented my compiled classes then I deployed it in jetty server.
then i ran my test cases from http client and i was expecting cobertura.ser file to be generated at server but it is not generated when I stop jetty server.
please let me know how can i get code coverage for web application from jetty.
I'm using java 1.7
I am not using maven.
I followed the steps based on below link.
Java: measure code coverage for remote scripting tests .
This is probably due to the fact that Cobertura dumps coverage data when the VM exits, not when the server stops.
You can have a look at the alternative maven plugin I wrote for Cobertura and its companion example project:
https://github.com/QualInsight/qualinsight-mojo-cobertura
https://github.com/pawlakm/qualinsight-mojo-cobertura-example
The documentation provided by the first link describes how to configure Jetty and with a small extension that dumps coverage data during server stop (see "Gathering IT test coverage data when running instrumented code on Jetty") This documentation is for Jetty 9.3, however the second link provides running examples for Jetty 7.6, 8.1, 9.2 and 9.3.
In your context, you should use wartest-jetty9.2.x module as it aimed at Jetty 9.2.x and JDK1.7. Have a look at the module's (and its parent) pom.xml file, as well as jetty.xml file
Do not hesitate to give feedback and ask questions, I'll do my best to help you.
Regards,

Junit unable to load properties file of web aplicaion

I have piece of code in webapp which loads a file from WEB-INF classes folder
ex-
PropertiesHelper.class.getClassLoader().getResourceAsStream("/test.properties);
I am writing a junit for the above method, but when test is executed it is unable to find/load properties file. I have added the properties file in test resources but still it is unable to load it.
If I change the main code and remove slash - '/', then junit works but code will not work when deployed in webapp.
How to write junit for the above case?

Visual Studio 2012 Coded UI Testing of Web Application - Code coverage

I have a web application. I am using VS 2012 Coded UI for testing the web application. I have recorded the test and running it, and it works fine. But the code coverage window gives code coverage of the test project only, it doesnt give code coverage of the website project and other dll project which is referred in the web project.
I have added the testsetting file in the solution and selected the same.
Any clue?
Couple of things to verify
a) Have you added all these assemblies into the code coverage configuration's list of assemblies via the testsettings?
b) Is your deployment of the web app happening as a part of your test run? If so then you should ideally have the "instrument in place" option selected