SimpleCov code coverage comparize with last build in Jenkins - ruby

I have situation where I want to compare code coverage of last Jenkins build from current Jenkins build so if current Jenkins build code coverage is low then last one , build should unstable or failed
Is that possible with any Jenkins plugin or do I need to do some stuff with SimpleCov?

You can use the RUbyMetrics Jenkins plugin: https://wiki.jenkins.io/display/JENKINS/RubyMetrics+plugin
along with with simplecov-json and simplecov-rcov gems.
So you need to add this to your rspec_helper:
require 'simplecov'
require 'simplecov-json'
require 'simplecov-rcov'
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter,
SimpleCov::Formatter::RcovFormatter
]
SimpleCov.start

Related

jenkins performacne plugin with pipeline project,Compare with specific build

I have created jenkins pipeline project where running jmeter test.
here i am not able to find option /attribute which can be passed/added to perfReport command with which i can comparr current run with specific past build number.
current perfreport options i do see are
perfReport filterRegex: '', relativeFailedThresholdNegative: 1.2, relativeFailedThresholdPositive: 1.89, relativeUnstableThresholdNegative: 1.8, relativeUnstableThresholdPositive: 1.5, sourceDataFiles: 'results.csv'
You need to add the following stanza to your pipeline:
modeEvaluation: true, nthBuildNumber: 1
change this 1 to the build number you would like compare the current result to.
More information:
Jenkins Pipeline Syntax
How to Use the Jenkins Performance Plugin
How to Build Reports with Peformance Plugin

Reduce Travis-CI building time for Gradle

I've started a new project of SprintBoot and Kotlin and I wanted to use Travis-CI as my CI server.
I also wanted to use codecov to collect the reports about my code coverage
Everything seems to work perfectly beside one thing, My project currently is an empty SpringBoot project that contains (and no tests) and the build itself takes up to 2m (mostly due to the time it takes to install Gradle).
I checked on their site and saw some optimizations to the build, but they're looked to early for this stage of the project (e.g. parallel tests execution).
Am I missing something? is 2m is the baseline for Travis-CI building time?
My current configurations for Travis :
# This enables the 'defaults' to test java applications:
language: java
# We can specify a list of JDKs to be used for testing
# A list of available JDKs in Trusty can be seed in:
# https://docs.travis-ci.com/user/reference/xenial/#jvm-clojure-groovy-java-scala-support
jdk:
- openjdk11
before_script:
# makes sure that gradle commands can be executed on build
- chmod +x gradlew
script:
# Makes sure that gradle can be executed.
- ./gradlew check
# Generates the reports for codecov
- ./gradlew jacocoTestReport
# This is to enable CodeCov's coverage
# If a build is successful, the code is submitted for coverage analysis
after_success:
- bash <(curl -s https://codecov.io/bash)
You'll want to cache to improve speeds of your build on Travis. Gradle has a dedicated guide on building on Travis: https://guides.gradle.org/executing-gradle-builds-on-travisci/
For caching, scroll down to Enable caching of downloaded artifacts

Using SimpleCov in a Ruby Project

I am trying to use the simplecov gem in a Ruby project. However I have failed miserably. Here is what I've done until now.
My project structure is:
ProjectFolder
- lib
- test
I have my tests in test and source code in lib. I have created a test_helper.rb in the test directory and added the following.
require 'simplecov'
SimpleCov.start
Then I put `require 'test/test_helper.rb' in every test file. What happened was it sometimes created some report, and sometimes didn't. And when it did it was inconsistent.
All the tutorials I found was for Rails so I turn to StackOverflow once more, to show me the way.
Rcov/SimpleCov will only report the coverage of the tests ran.
For a full coverage report, you must ensure that the full test suite is ran as the last test, to build a full coverage report.
You will also want to make sure it is the first require in your test_helper.rb file.
From the documentation:
Note: If SimpleCov starts after your application code is already
loaded (via require), it won't be able to track your files and their
coverage! The SimpleCov.start must be issued before any of your
application code is required!

Rake file with Jenkins (Cucumber, watir-webdriver)

I've started with watir and cucumber a while ago and have been trying to run my project with Jenkins. I have a watir Project (watir,cucumber) in C:\project_name. I have rake file in the project also and when I run it in CMD everything goes ok and tests are succesfully executed --> C:\project_name>rake
Rakefile I'm running looks like this.
require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features) do |t|
t.profile = 'default'
end
task :default => :features
I have tried to execute Rake file with Jenkins but unable to make it work. So far what I have done with Jenkins (Running in localhost:8080)
1) Plugins installed eg. cucumber-reports, Jenkins Rake plugin
2) Tried to add New job --> Build a free-style software project
I really don't have idea how to make Rake file to work with Jenkins. I was hoping to get these nice reports (cucumber-reporting) available through Jenkins.
If someone can help me with this it would be more than perfect.

How to get Hudson to see rcov results?

I am currently working to integrate rcov with our Hudson server.
I am able to run rcov via rake and get the results with out issue (see rake file below). When I run things via Hudson - calling the rake task - the tests with coverage are clearly generated and displayed in the console.
But at almost the end, the following shows up in the console:
** Execute test:coverage
Recording test results
No test report files were found. Configuration error?
Build wasn't successful, skipping rcov coverage report
Finished: FAILURE
Rake task
desc 'Aggregate code coverage for unit, functional and integration tests'
task :coverage => "test:coverage:clean"
%w[unit functional].each do |target|
namespace :coverage do
Rcov::RcovTask.new(target) do |t|
t.libs << "test"
t.test_files = FileList["test/#{target}/*_test.rb"]
t.output_dir = "coverage"
t.verbose = true
t.rcov_opts << '--rails --aggregate coverage.data'
end
end
task :coverage => "test:coverage:#{target}"
end
Going to coverage/ I see output file. The coverage.data file is present as well.
Any thoughts on what might be going wrong here? Am I missing something blindingly obvious?
Hudson will not pull the coverage results if the build has failed further up the chain. I ran into this issue when one test was failing, and could not figure out why coverage was not being reported.

Resources