Add custom Jenkins Cobertura metrics
I'm covering some legacy code with tests, and the initial goal was to get the line coverage close to 100%. That is good to have such high coverage, but I feel like falling into an XY Problem. First of all, some lines of code are impossible to test without proper mocking, and mocking is not reasonable in that case. For example in the function just logs into an external log service, there is no need to test the exact format of the log message.
Personally I think that the only valid thing to cover with tests is a requirement. It is not something that has to be written, but this is a hyperplane that divides possible implementations into valid and invalid ones.
I'm thinking on an idea to implement something like a database of reqirements, were each test case would register the requiremens this test case covers. After running the build in Jenkins I may compare the list of the requirements that were registered by the tests run with the whole list of the requirements. This would have some sense only if I could expose this metric in Jenkins Cobertura together with class/line/conditionals coverage.
Is there any [easy] way to customize the list of metrics and to add a new one into Jenkins Cobertura?
See also questions close to this topic
-
Trigger Jenkins build for each commit on develop branch
I build a freestyle jenkins pipeline that executes sonarqube scanner on develop branch and sends slack notification after the build finishes with the results, when I build the pipeline manually it works as expected.
I used Bitbucket Plugin to trigger the build after each commit, but it's only working after I changed the pipeline to track the master branch instead, and the pipeline is not triggered on develop automatically. I don't know where's the problem exactly.
I'm using ssh access key to connect to my private bitbucket repository, and my webhook is returning 200, thanks for your help.
-
Jenkins Active Choice Reactive Reference Parameter Formatted HTML in MultiBranch pipeline job get current branch name in script
I am trying for a lot of time to get the current branch name in MultibranchPipeline Job inside an Active Choice Reactive Reference Parameter Formatted HTML parameter script block
[ $class: 'DynamicReferenceParameter', choiceType: 'ET_FORMATTED_HTML', name: 'TestParam', omitValueField: true, description: 'Test.', script: [ $class: 'GroovyScript', fallbackScript: [ classpath: [], sandbox: false, script: ''' return """ <p>FallbackScript. Error in main script</p> """ ''' ], script: [ classpath: [], sandbox: false, script: ''' String branchName = env.BRANCH_NAME return """ <p>${branchName}</p> """ ''' ] ] ]
The thing is that, I believe, the
BRANCH_NAME
param is injected after you press theBuild
button.I've tried a lot of things, and I mean, A LOT, still I didn't manage to find a way. The
scm
variable doesn't exist as well, I tried to find something with thejenkins.model.Jenkins.instance
but no luck.Is it possible? I would love to ask this question on their Github repo, but issues are not allowed to be opened. Also to open an issue on Jenkins you need a Jira account or something. SO is the only place.
-
Jenkins - Build Other Projects conditions
I’m not exactly a seasoned Jenkins user (yet), so I’m calling out anybody who is much more knowledgeable about Jenkins than I am! 😊
At a customer, we are using Jenkins in order to trigger builds to launch Tosca tests using the Tricentis CI plugin. After this build is complete, we trigger another job in order to generate a report.
We would like to customise the conditions in which the second build would be triggered, but we are always limited to the three following ones: Click here to display image
I’d like to know whether it’s possible to add other conditions such as “Trigger only if the build fails / is unstable”
Is there a plugin that could be used for that, or another workaround…?
Thanks in advance for any pieces of advice.
Best regards,
-
How do I create a test for my services controller (Jest)?
I'm trying to create a test for my Animals List Services Controller, making sure the database query is tested. Right now with what I have, I have been able to mock the database query call to ensure the query is being called with the right parameters. However, i'm also trying to mock the return values from the database query call. I'm not sure how to mock dbResult in "services.ts" to get the rows property. Please I need some help, not sure how to do it. Thank you in advance.
I believe I was able to mock the database query call, however, is there a way to refactor or create a test to mock the return call of dbResult?
services.ts
import db from '../../modules/db'; import { DBGenericDataResponse } from '../../types/models'; export async function GetAnimalsList(): Promise<DBGenericDataResponse> { const lQuery = `select animalid, description from animal where active=1 order by sortorder, description`; const responseMessage: DBGenericDataResponse = { code: 200, status: 'ok', message: '', count: 0, data: [], error: '' }; try { const dbResult = await db.query<any>(lQuery); responseMessage.message = 'Animals Returned'; responseMessage.count = dbResult.rows.length; responseMessage.data = dbResult.rows; } catch (err) { responseMessage.code = 400; responseMessage.status = 'error'; responseMessage.message = 'Error retrieving Animals List'; responseMessage.error = err; } return responseMessage; }
ServicesTest.spec.ts
import * as Services from '../../../../src/controllers/animals/services'; import db from '../../../../src/modules/db'; describe('GetAnimalsList', () => { afterEach(() => { jest.resetAllMocks(); }); it('should call the database with the correct query parameter', async () => { const dbMock = jest.spyOn(db, 'query'); const response = await Services.GetAnimalsList(); expect(dbMock).toBeCalled(); expect(dbMock).toHaveBeenCalledWith( 'select animalid, description from animal where active=1 order by sortorder, description' ); }); });
-
Software Engineering cum MySQL Project (Railway Management System)
I have been given a software engineering project to design an ER diagram for Railway Management System. I have already prepared the ER diagram but I am unable to procced further and design it's relational schemes and the normalization. I urgently need help with my project as the due date is near...I have a attached the ER diagram for the kind reference.
Link to ER : https://drive.google.com/file/d/1orcn_f5Ozs9RJd93tMfT9foK7_umjdGk/view?usp=sharing
-
Testing auth not covered case in sandbox
According to plaid docs, plaid does not support auth for 10% of bank institutions.
Is there a way to test this on sandbox environment?
-
unable to find tools.jar
I am on Mac and trying to generate Cobertura code coverage report but I am getting
Could not find artifact com.sun:tools:jar:0
at the specified path/usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Content/Home/../lib/tools.jar
which is similar to [https://stackoverflow.com/questions/5616318/how-do-you-address-the-issue-of-a-missing-tools-jar-in-a-jdk-in-mac-os-x].
The weird thing is that when I go to:
/Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home/lib
, I still cannot seetools.jar
.Secondly, I am not sure why the the error is showing
15.0.2
while the JVM has11.0.6
-
Cobertura coverage failing
I am running into issues similar to [https://stackoverflow.com/questions/25432810/error-when-trying-to-use-org-codehaus-mojocobertura-maven-plugin2-6].
LOGS: Execution default-cli of goal org.codehaus.mojo:cobertura-maven-plugin:2.6:instrument failed: Plugin org.codehaus.mojo:cobertura-maven-plugin:2.6 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:0 at specified path /usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Contents/Home/../lib/tools.jar
RESEARCH:
When I do
java --version
, I get:java 11.0.6 2020-01-14 LTS
Upon searching SO, I found that since I am on the JDK 11, the
tools.jar
has been removed [https://stackoverflow.com/a/60549167/13241701]. When I run the jacoco, the test cases run. ButISSUE: I want to report the cobertura coverage report only.
Can I get some help?
-
IntegrationTest fails with cobertura
I wanted to generate the coverage report for my project. For that, I found that I can use cobertura [https://stackoverflow.com/questions/2006014/how-to-generate-cobertura-code-coverage-report-using-maven-from-hudson]. I added the following in
pom.xml
forjava 11
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.5.2</version> <configuration> <classesDirectory>./test</classesDirectory> <formats> <format>xml</format> </formats> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>cobertura</goal> </goals> </execution> </executions> </plugin>
When I am running
mvn cobertura:cobertura
I am gettingjava.lang.ClassFormatError: Nest member class_info_index 35 has bad constant type in class file
which is not closed, I think. When I am runningmvn clean package
the file runs but is not producing the.xml
file. Is there any way in which I can achieve the coverage report. -
How to you requirements.txt in python3.6?
I have requirements.txt including versions of packages and bash script that compiles several python scripts *.py. How to change the compilation command python3.6 *.py to use the version of packages in requirements.txt? Or how to create an installation package? Thanks
-
How to write a nested if/else statement in R4j (For Jira exported word)
I would like to export a requirement and I got 2 different types of requirements:
- Functional System Requirement
- Non-Functional System Req
each time I get the same requirement exported twice. this is what I tried:
[[\if $.issuetype =”Requirement”]] [[\if $."Requirement Subtype" =”Functional System Requirement”]] **Got here Req1** [[/if]] [[/if]] [[\if $.issuetype =”Requirement”]] [[\if $."Requirement Subtype"= "Non Functional System Req"]] **Req1 again** [[/if]] [[/if]]
Does anyone know what I did wrong that in getting each requirement twice and not by the field "Requirement Subtype"? Thanks!
-
Jira exporting Word templates
Does anyone know what happens to the file when it's being exported? I'm succeeding to export a file with requirements and after making some small changes it cant get uploaded.
So I'm thinking there is some kind of conversion that happens when the file is being exported from Jira.
anyone knows what?