Web Application Code Coverage using JaCoCo - java

I have been assigned a task where I want to generate the code coverage report of web application execution (development code) when a manual or automation test script is executed, I have to identify (using any tool) what percent of development code has been executed against that particular action.
After doing my RnD, I found that this can be achieved using JaCoCo (Java Code Coverage). JaCoCo uses class file instrumentation to record execution coverage data. Class files are instrumented on-the-fly using a Java agent. I have used the java command in the java agent flag.
Points to Mention
Application front-end is Angular, backend is Java/BPM and is deployed on JBoss Server.
Backend code contain multiple modules.
Testcase are executed from my local machines, that hits the application deployed on the server.
APPROACH
I have added the below mentioned command in /app/JBoss-EAP-7.2/bin/standalone.sh file because this is the file that is executed when the server starts.
Javaagent:<path_to>/jacocoagent.jar=classdumpdir=<path_to>/jacocoClassDump, destfile=<path_to>/jacocoST.exec
Restart JBoss server. [After this jacocoST.exec file is created in the respective folder]
Run automated testcase using maven on my local machine.
Stop the JBoss server. [so that jacocoST.exec file is updated]
Run the command:
java -jar <path_to>/jacococli.jar report <path_to>/jacoco-it.exec -- classfiles=<path_to>/jacocoClassDump --html /app/Jacocoreport --xml cov.xml
The above steps show error Can't add different class with same name
Why do I get the error "Can't add different class with same name"?
The FAQ that I’ve come across from JaCoCo Official Documentation
For coverage report generation all classes within a group must have unique names. You get this error during report generation if JaCoCo is supplied with multiple different class files with the same name. To fix this remove those duplicate classes or create separate reports or report groups for each version.
The main problem is the error which I am getting. According to FAQ, they suggest to delete duplicate files but there are no duplicate class files (each class files has unique number at the end).If somebody has done such work so please guide me, Are the steps which I followed right?

Related

How to trigger schemaSpy method/interface to generate diagrams without running command

Imported schemaSpy:v5.0.0 maven dependency using this : https://mvnrepository.com/artifact/org.jumpmind.symmetric.schemaspy/schemaspy
Also added the schemaSpy.properties file with up to date database properties.
But once I run the project Nothing is being generated on the specified path , How to invoke/trigger schemaSpy job using maven dependency.
There is no method/interface exposed on how to trigger the schemaSpy job to generate the images in specified directory on some user based input (Could be some database credentials entered by end user in runtime environment to generate relationship diagrams).
Note:
Its generating diagrams properly while running command in terminal, Wanted to generate the diagrams in runtime environment based on user's input using some exposed methods/interface .

How to generate Swagger's "api-docs" during build process?

I think this is a trivial use case, but can't find anywhere about it.
Our build should have 2 parts that are related to Swagger:
Run regular swagger and create the JSON (available in \api-docs url) and other Swagger-related items.
Create DTOs from the JSON.
I want to run step 1 as a part of the build process.
Details:
Currently, our project has springfox-boot-starter (3.0.0) that includes Swagger-UI. This allows the api-docs to be available when the server is online (I believe this is created on runtime, and doesn't display an existing JSON file). So I can fetch that JSON from the browser.
I added to Maven's pom.xml file the awesome openapi-codegen (openapi-generator-maven-plugin), and so when I set the plugin to point on the JSON file (created when the server was online) and run mvn clean install it does what I need in step 2: generates DTOs.
However, I can't find anywhere how to do step 1 (create the JSON) during the build process, when the server is offline.
I believe this is very common use case so this is surprising, since generating DTOs is needed on the build process and shouldn't be dependent on a running server.
I know there is a project called Swagger2Markup in GitHub but it is un-maintained.
Thanks!

gradle specify classpath via command line arguments

I would really like to do something like ./gradlew build -cp /$HOME/my/custom/testerLibrary.jar but I cannot find a straight answer anywhere. I have a special case where I need to add a jar to the class path because the class that I use for manual testing requires it, but nothing else in my project needs it and I don't want to include it in my build.gradle.
Should I create 2 projects where project A is run manually to debug project B?
You can create two JARs from the same source code:
the production application
the manual-testing application
The manual-testing application (2 in the list above) could be created using a Gradle task that appends the required JAR to the classpath:
task createManualTestingApp(type: JavaExec) {
classpath += "/$HOME/my/custom/testerLibrary.jar"
// ...other configuration...
}
If you want the task that creates the production JAR and the manual-testing JAR to be identical, except that the manual testing JAR contains the augmented classpath, this can be done by creating two tasks that extend the same type: How to extend the behavior of a Gradle task for a new task type?
Opinion: From a testing perspective, it is not ideal to have a JAR that is included in the manual-testing application but not in the production application. This results in a test application that is different than the production application. For example, what if that JAR includes something or changes the behavior of the application that causes the manual tests to work but the production application fails because it is missing that JAR? Depending on the nature of the JAR, this may be benign, but it is important to consider when deciding that the test and production applications will be different.

How to integrate offline JaCoCo exec files from Maven multiproject build into SonarQube

I have a Maven multiproject build. The unit tests are using PowerMock 1.6.6, and I've managed to generate individual Jacoco (0.7.8) exec files for each module using the "offline" process. I also have a single module that uses the "report-aggregate" to generate a single JaCoCo report.
I'm now trying to integrate with SonarQube 5.6.5, using sonar-scanner 2.8.
Using this doc page I naturally constructed a command line setting the "sonar.jacoco.reportPaths" property to a comma-separated list of paths to the "jacoco.exec" file in each child module. This appeared to have no effect. I saw a message in the output saying "INFO: JaCoCoSensor: JaCoCo report not found : <mycurrentdirectory>\target\jacoco.exec".
So, I instead set property "sonar.jacoco.reportPath" to the same comma-separated value. This at least had an effect, but it confused the scanner, as it obviously expected this to be a single location.
I then tried setting that property to just the first of the several "jacoco.exec" files. That at least completed, but with minimal coverage data.
How do I proceed? Am I instead supposed to somehow use the Jacoco "merge" goal to merge all of my jacoco.exec files into a single file, and specify that, or is there a different undocumented property that allows a list of paths to files?
I verified that the advertised "sonar.jacoco.reportPaths" property only works in SonarQube versions 6.2 or newer (the docs have apparently been updated to reflect this).
Therefore, I moved forward with implementing "merge", specifying the filesets for all the modules. It took a while to get the data correct for that fileset list (Maven, like many frameworks, often says nothing when your configuration data represents files or components that don't exist).

Error while running Storm MultiLang using Python

I am following a course work on Apache Storm from Udacity. The version of storm being used is 0.9.3
One of the exercises there is to run a topology which contains a bolt written in Python. Briefly here are the steps followed. For the purpose of this exercise my source directory is src and my package is udacity.storm
Create directory called resources/ under udacity/storm. Place two python scripts there - splitsentence.py and storm.py.
Create a bolt SplitSentence under the package udacity.storm. SplitSentence bolt derives from ShellBolt and implements the IRichBolt interface.
Build the topology using maven. During the process also package the resources/ directory within the JAR file.
Submit the topology to storm using the command storm jar target/mytopology.jar udacity.storm.MyTopology.
The topology loads up and dies immediately and I see the following error on the console
The storm client can only be run from within a release. You appear to
be trying to run the client from a checkout of Storm's source code.
I took a look at the storm.py code and figured out that this would happen if the lib/ directory is not present in the directory from where the python script is executing. After putting in some debug statements I identified that the python script runs from the following location :
/tmp/06380be9-d413-4ae5-b387-fafe3acf3e65/supervisor/stormdist/tweet-word-count-1-1449502750
I navigate to this directory and find that the lib/ folder is absent.
The Storm Multilang page does not give much information that would be helpful for beginners to debug the problem being faced.
Any help to solve this problem is greatly appreciated.
As the error says you try to run within the source code. Just download the binary release https://storm.apache.org/downloads.html and follow the setup instructions https://storm.apache.org/documentation/Setting-up-a-Storm-cluster.html
Afterwards, you can prepare your jar file and submit to the cluster via bin/storm jar yourJarFile.jar (see https://storm.apache.org/documentation/Command-line-client.html)
There is no need (as long as you don't want to work on Storm itself) to download the source code manually. Just include the corresponding jar files from the binary release to your project. If you use maven (and only run in local mode), just include the corresponding maven dependency (see https://storm.apache.org/documentation/Maven.html); there is no need to download the binary release manually for this case.
I got the problem after some fair amount of looking around. Actually, the problem is not within the instructions themselves but because the storm.py file I had included in my resources directory was of an older or incorrect version - I had obtained the URL via a Google search and probably ended up with an incorrect one.
The storm.py to be downloaded is from this Github link. I am now able to run the exercises successfully.
Thank you all for your help. I will ensure that I post this up in Udacity forums so that people are aware of the confusion.
In case anyone else experiences this problem:
I had the same issue. However, I couldn't resolve it by copying storm.py from the binary release to my resources directory.
My initial error was "AttributeError: 'module' object has no attribute 'BasicBolt'"
You can add the correct Maven dependency to your pom.xml which will copy the correct dependencies into your JAR. Add the artifact "multilang-python", groupId "org.apache.storm" with version matching your Storm version, then run the clean and package goals to produce the updated JAR file.

Categories

Resources