Sonarqube API single class test coverage - api

I am trying to retrieve the unit test code coverage for individual classes through the SonarQube API (Sonar version 4.1.2). Everything is working fine, and I can see the metrics okay when I go directly to the sonar dashboard and go to the coverage tab for a class:
93.9% by unit tests Line coverage: 97.9% (285/291) Branch coverage: 85.0% (113/133)
Can anyone tell me the correct call to retrieve this same/similar information through the sonar API interface please? I've already had a look at the documentation at http://docs.sonarqube.org/display/SONAR/Metric+definitions and can get test coverage metrics back at project level but I can't see how to construct a query for individual classes.

I think this is what you are after
[hostname]/api/resources?resource=[com.test]:[module-name]:[fully qualified class]&metrics=coverage,branch_coverage
I have added an example below.
http://sonar-server/api/resources?resource=com.test:module:com.test.service.impl.CheckServiceImpl&metrics=coverage,branch_coverage
I looked at the page you shared and used this also :
http://docs.codehaus.org/pages/viewpage.action?pageId=229743280

api/measures/component_tree is your friend
result = session.get(
SONAR_BASE + "api/measures/component_tree",
params={"baseComponentId": COMPONENT, "metricKeys": "coverage" )
)
gets you coverage down to the file level. You should be able to only get the files with the "leaves" strategy.

Related

How to configure and execute multiple Tags for junit in Intellij in Run/Debug Configuration

I have some junit5 tests in my project, I have used the #Tag annotations for some of the classes. I am successfully able to run those classes from Intellij via configuring the Run/Debug like below. This looks good when I use single type of tag eg. suite-three
Image-1
The problem I am facing is, Now I want to run classes with two different tags at the same time, since I am executing the some tests Parallelly. Inorder to achieve this I have created an intermediate Bootstrap kind of class where I am using #SelectClasses annotations class to pass this 2 Test classes which I wish to execute like this
Image-2
. So here when I configure the Tags from Intellij like below screenshot
Image-3
Notice I am sending two different tags, but Intellij doesnt executes the Test class and it keeps on giving me this message "No Tests Found".
Any help would be mighty helpful to me.
We can use | pipes for running multiple classes together viz. tag-1 | tag-2 this will run all the classes which are tagged with tag-1 OR tag-2. I am running this classes parallelly with JUnit5's new method with usage of junit.jupiter.execution.parallel.enabled = true

Cucumber-JVM: Cucumber After hook executed two times/twice

I"m implemnet Cucumber Testng for learning purposes. I"m realizes that #After hook method is executed twice. I can confirm it with debugging set and test report output. I"m only execute 1 feature file and my test report has two same class names.
Do you guys know why?
There is warning in the feature file called Multiple Definitions "Volare Collector Home Page opens in browser".
Please help. Thanks.
Please download my source code from this link.

How to integrate Galen reports in Jenkins

I've started to use Galen framework to test the layout of my website pages and I also have my other test, written in Selenium, integrated into Jenkins.
I'm using Java+JUnit+Maven and I would like to know if anyone has managed to integrate the Galen reporting into Jenkins and how.
Because for the moment I am using something like:
assertThat(layoutReport.errors(), is(0));
which tells me if there were errors in the tests but not where.
Thanks!
P.S. If someone with reputation could make the tag galen-framework so that we can group these type of questions, it would be great :D
In your case you could use Galen for generating HTML reports as it normally does when you run tests with it. Though you will have to manage the creation of GalenTestInfo objects.
Here is how the HTML report generation works. Imagine you have somewhere obtainAllTests method defined which returns a list of all executed tests.
List<GalenTestInfo> tests = obtainAllTests();
new HtmlReportBuilder().build(tests, "target/galen-html-reports");
Somewhere in your code you could create a GalenTestInfo and add it to some collection:
GalenTestInfo testInfo = GalenTestInfo.fromString("Here goes the name of your test");
Once you have done the layout checking and obtained LayoutReport object you could add this report to the report of the test. Here is how you can do it:
LayoutReport layoutReport = Galen.checkLayout(driver,
specPath, includedTags, null,
new Properties(), null);
testInfo.getReport().layout(layoutReport, "A title for your layout check");
You can find more insights in this project https://github.com/galenframework/galen-sample-java-tests. It has a basic setup for Galen tests in Java + TestNG + Maven. The reports in it are collected in a singleton GalenReportsContainer. There is also a reporter implemented in GalenReportingListener which takes all those tests from GalenReportsContainer and generates HTML reports.
You can see a full example for Java (TestNG and JUnit) and JavaScript here:
https://github.com/hypery2k/galen_samples.
I use the HTML Plugin together with Jenkins, see example here

Integration between Rally and Robot framework?

Does anybody know of an integration between Rally ALM and robotframework?
I'm looking for something that would log test results in robotframework back to Rally test cases.
With the pyral rally module for Python, seems like it could be fairly straightforward.
As far as I can tell there is nothing out there to do this-- but its pretty easy to do, only needing about 50 lines of python code for a simple integration that logs robot framework to Rally test case results.
In my case, I have it log results for any test who's name starts with a Rally test case id: (e.g. "TCXXXX My Test Name").
The trick is to user the RobotFramework listener API (See: Elapsed time and result of a test in variables) and pyral, the Rally python API. Key for my needs was to define an "end_test" listener:
def end_test(self, name, attrs):
match = re.search('^(TC\d+)\s*(.*)', name)
tcId = match.group(1)
testName = match.group(2)
if tcId:
tcr = self.__logTestCaseResultToRally(tcId, testName, attrs)
self.__cleanTestCaseState()
In robotframework, I include this listener file, which also has some additional methods to add attachments and other information like notes to a test result (these can be directly called as libraries in your robotframework file):
def addAttachment(self, attachment):
if os.path.isfile(attachment) and os.access(attachment, os.R_OK):
self.attachments.append(attachment)
This method simply saves the attachment path in the listener object so that when end_test() is called, it has access to the file names to attach to the rally test case. __cleanTestCaseState() zeros these out so they are cleared before the next test cast starts.
Actually, I've never used Rally!
But in my opinion, With robot framework, I like using Testlink for testcase management system & jenkin for CI control system :)
You can search in the internet for installation.
Hope it useful :)

Issue with the karate parallel runner

I wanted to see if anyone else might have observed the same issue. I looked in the project for any open/closed issues that might be like this but did not notice any.
I noticed that when I use the Karate Parallel runner (which we have been using for a while now), that every GET, POST, DELETE request gets called 2x, observed in the karate logs which came in the console.
When I do not use the Karate Parallel runner only a single request is made.
I noticed this when performing a POST to create a data source in our application. When I went to the applications UI to verify the new data source was created, I saw 2 of them. This leads me down the path to research further what might be happening.
Using Karate v0.9.5 with Junit 5
minimalistic Example -
https://drive.google.com/file/d/1UWnNtxGO7gr-_Z80MLJbFkaAmuaVGlAD/view?usp=sharing
Steps To Run The Code -
Extract ZIP
cd GenericModel
mvn clean test -Dtest=UsersRunner
Check the console logs API scenario get executed 2X
Note - It works fine for me for karate V0.9.4 with Junit 5
You mixed up parallel runner and JUnit runner and ended up having both in one test method. Please read the documentation: https://github.com/intuit/karate#junit-5-parallel-execution
Note that you use the normal #Test annotation not the #Karate.Test one.