How to get karma javascript junit xml reports into sonar - junit

Is there a karma reporter which can be used to generate a results.xml file which is compatible with the sonar Generic Test Coverage plugin? Or alternatively a parser for the junit file which is output by karma-junit-reporter and which will work with the generic plugin?
I am using SonarQube 5.3 and Karma / Jasmine
I want to import the junit reports that come from karma into SonarQube but cannot see a way to do this easily. Something like https://www.npmjs.com/package/mocha-sonar-generic-test-coverage for karma
FYI I have seen
karma-junit-sonarqube-reporter (https://www.npmjs.com/package/karma-junit-sonarqube-reporter) but that seems to expect the name of the test to match the path to the file which is too restrictive for me.
karma-sonarqube-unit-reporter seems to be unfinished
grunt-karma-sonar seems to rely on jstestdriver which is deprecated

I managed to achieve this by doing the following.
To get javascript junit reports into sonar
find and download sonar-karma-test-report-plugin-1.0.0.4.jar which is not available via the update center
put jar file in /usr/local/Cellar/sonar/5.3/libexec/extensions/plugins and restart sonar
Tell karma to omit the name of the browser
junitReporter: {
useBrowserName: false
}
Get Karma to create a junit xml file via the normal karma-junit-reporter and have it call the file TESTS-xunit.xml (I had the file called test-results.xml and sonar would not detect it WTF)
In the sonar-project.properties file set sonar.javascript.karmajstestdriver.reportsPath=reports/js/unit-components/results/
call sonar-runner
Sonar requires the path to the test file in order to process the report. Jasmine does not make this available to the reporter. My understanding is the sonar plugin iterates over xml file and finds the classname for each test which has the test name (ie my cool tests) and does a string replace to change that to the location of the file

Related

Testcafe: find current working directory from test

I have a working TestCafe test suite which generates a custom xml report generated by code in the test suite. I would like to place this report in the "standard" ./results location that TestCafe uses for its reports, but I can't find an option to retrieve the current working directory (e.g., the bash pwd command).
I'm getting it by adding export pwd=$(pwd) on the command line when I run the test, but I wonder if there's a built-in mechanism in TestCafe to do this?
If you run the tests from the command line, you can just use the reporter option as follows:
testcafe chrome test.js --reporter xunit:results/output.txt
See this question for details: How to save report results from console to a file (TestCafe)?.

How can jenkins find junit.xml in a zip file?

I am running Jenkins on a script, that generates a junit.xml report file and other files. However, all those files are zipped by the script, hence Jenkins cannot find it.
Is there a way to make Jenkins unzip the .zip file , find my particular junit file and generate the run results ?
All this is in Linux.
Thanks
Jenkins has the ability to execute arbitrary shell commands as a build step, just add the 'Execute Shell' step to your build and put in the commands you want (presumably 'unzip' would be among them).
Once you've extracted the xml, provided your internal tool generates it using this schema the JUnit plugin just needs the path you extracted to and it will show the results on the build page.
If you have the option, I would really suggest executing your tests via gradle or maven, as outputs from those tasks will produce a report that Jenkins (and other tools) can already read, and can streamline the job setup process for your users. But, if you can't get away with that, the above should work for you.

Custom Reporting to Jenkins

I'm trying to hook up our own private testing tool to Jenkins. I'm able to run the test through the command line and create a report on my local machine. I will need to convert that report to xml JUnit format, specifically for Jenkins. Once that is done, how do I associate the xml file that was just created to the most recent job. This way the correct report gets put with the correct job?
The way Jenkins works is simple: you create a job and Jenkins runs it. Every run of a job is called a build. If you configure the job to look for test report files at the end of a build, the test reports are loaded and presented in the Jenkins UI. There is no way to submit test reports to a build outside of the build or after the build.
Usually this is not a problem. You run your test program/script as part of the build and it produces xml files in the JUnit format. When all the build steps are done, Jenkins looks for the xml files and loads them. You have to tell Jenkins to do it, though. You open the job configuration and you add a new post-build action titled "Publish JUnit test result report". Then you give Jenkins a pattern it uses to search for the files. You can use **/*.xml which means Jenkins will look for all *.xml files in every directory and subdirectory. Or you can e.g. use **/testreports/*.xml if you know where the test reports are going to be.

JMeter load testing with JUnit from Selenium IDE

I have problem with JMeter not picking up my JUnit test.
What I did:
got JMeter and extracted
created JUnit test through Selenium IDE and exported as JUnit4(WebDriver)
try that test runs when executed (in IntelliJ)
created JAR of the class file
placed JAR into jmeter.home/lib/junit
started jmeter
created new thread
added new sampler for JUnit request
However when I check "Classname" drop down my test is not listed there.
Does anyone know why test is not recognised by JMeter?
check whether scripts exported using junit4.
If yes, then select "search for junit4 annotations" check box. surely it will display.
After creating Junit jar file . Place the jar file in the
jmeter.home\lib not in jmeter.home/lib/junit.
After that Restart Jmeter.
Now add thread group to jmeter and Junit Request sampler.
Observe that the Classname apperas in the drop down list

Jenkins MSTest Issue

I have configured Jenkins as the CI for a project which is using Mercurial as the source control management. I'm using MSTest plugin in Jenkins to see the test results and I have written a bat command to generate test result file
del results.trx
mstest /testcontainer:Example\TestProject1\bin\debug\TestProject2.dll /resultsfile:results.trx
it gives an error in console saying File "Example\TestProject1\bin\debug\TestProject2.dll" not found"
when every build happens a folder is created under %WORKSPACE% having a new name (SYSTEM_My_Computer_Name 2011-06-08 13_04_11). In that the test dll is in a directory called out. How can I get path to that dll, because the directory name is changed for every build?
It is working fine when I used a absolute url like "c:\Example\TestProject1\bin\debug\TestProject2.dll"
How can we refer the newly built dll ?
Do I need to add test dll file in to the repository ?
Jenkins run bat files with %WORKSPACE% as the current directory.
As the error message indicates, the relative path to the test container is wrong. I can think of two things that can be the issue here:
The folder structure under %WORKSPACE% does not match your relative path. Adding a cd by its own in the bat file will reveal on the build output where this is. You can also use the links in the Jenkins web ui to browse the workspace.
You are building a different msbuild target in Jenkins, for example release. Then \bin\debug might not exist.
The folder "SYSTEM_My_Computer_Name 2011-06-08 13_04_11" is not created by Jenkins during the build, but it is created by the mstest when it is running the test. The root folder when the mstest is invoked is the workspace root folder, so the testcontainer file should be specify from the workspace root.
For example, say if the dll file is under C:\jenkins\jobs\\workspace\TestProject1\bin\debug\TestProject2.dll(assume your jenkins is installed under c:\jenkins).
The command should be (relative to the workspace root folder):
mstest /testcontainer:TestProject1\bin\debug\TestProject2.dll /resultsfile:results.trx