SonarQube Integration with Selenium to calculate Runtime Code Coverage - javascript

My current SonarQube version is : 9.2.4.50792
I am using Community Edition
Programming language being used : Python, JavaScript, html, css.
API’s has been developed using python Programming language.
I am trying to figure out how can I integrate Selenium (Automated testing framework) whose test cases are coded in python with SonarQube to generate a run time code coverage report in SonarQube.
When I am running test cases using selenium tool at that time the SonarQube should be able to generate code coverage report i.e. percentage of code covered while running the automated test cases, during that instance.
I have implemented the SonarQube, report has been generated but the code coverage report is shown as 0. I tried to calculate code coverage for python using coverage.py to generate an .xml file which can be integrated with SonarQube, major setback faced is how should I calculate coverage of API. The analysis done currently is static, I want to achieve runtime code coverage analysis.

Related

How can I run JEST unit tests that are written by users at runtime in a browser-based editor like Ace Editor, to test JavaScript code the users wrote?

I teach Javascript at college. I want to write course exams that need to run unit tests on the code that my students wrote.
I need to create exams that will run jest unit tests on the code that my students wrote.
much like edabit or codewars where you have challenges with predefined tests...
At some point the students are required to write their own jest unit tests and run it against their own code like you can do in codesandbox.
I'm using ace editor for now to allow students to write code in the browser. I need your help with the following:
What sort of Jest variations / configurations are needed to write pre-defined unit tests in order to test the students' code in the browser? 
What is the best way to run code written in a browser based editor? I assume a simple eval() is problematic and not secure... I need to run it in the browser so node.js is not an option.
How do you support importing/exporting of ES6 modules? Is it true that you need to write your own module bundler to execute in the browser? Is it the only way? Do any of the module bundlers out there support browser-based bundling?

Javascript unit testing with Jasmine and JSP

I am working on a project that uses JSP and Javascript. Now I have to write unit tests so I started using Jasmine for it and since the project is built using Maven, My goal was to run unit tests as part of continuous build and integration. So I thought of using jasmine-maven-plugin it uses PhantomJS for headless testing. I tried PhantomJS API to see whether it can load a JSP based webpage. Using the sample api I was able to create a screenshot of my JSP page. So I think PhantomJS can work with JSP.
My unit tests are heavily dependent on the JSP page but I was to not able to configure the Jasmine specRunner to use JSP, so that I can run my Jasmine tests as part of maven build.
Does anybody used Jasmine, Javascript, JSP combination for unit testing? Any help or comments will be highly appreciated. Thanks!

Azure documentdb how to develop server side?

as a total JavaScript beginner, how do I actually develop for it?
I mean, I've seen https://azure.microsoft.com/en-us/documentation/articles/documentdb-programming/ but there was no mentioning of a development environment.
Is there something like a visual studio project template for server-side javascript?
I use node.js so your mileage may vary if you are developing from .NET, but here's what I do:
First of all, I created an npm package documentdb-utils. It is a wrapper for the DocumentDB node.js package that makes it easier to do a bunch of things.
Then, I created npm package documentdb-mock to write tests for my stored procedures. The source code for documentdb-mock includes 4 example stored procedures along with a test suite for each using nodeunit. You can start with these as they exercise most of the server-side API.
After I have them passing my local unit tests, I write integration tests that exercise my system end-to-end including creating any necessary data for each test run. The only problems that I've found here with sprocs that I didn't see in my mocked testing had to do with reaching certain limits... although, documentdb-mock has been upgraded to simulate many of these now also.
I haven't open sourced this yet, but I have also written a parser/rewriter that will embed any require(d) packages into my sprocs before sending them to DocumentDB. This allows me to write and test in a nicely factored way on node.js even using downloaded packages from within my sprocs, but when they get pushed to DocumentDB any dependencies are automatically embedded inside of the function. I'll open source that at some point (probably adding it to documentdb-utils) but I can share it with you now if you desire.
Here are a few tools that I found helpful for development (especially server-side [by which we mean database-side] scripting):
DocumentDB Studio - https://github.com/mingaliu/DocumentDBStudio/releases
Sample Code - https://github.com/Azure/azure-documentdb-js-server/tree/master/samples/stored-procedures
Here is another nice open source tool for exploring data in documentdb:
documentdb.a7pl.us

Test driven JavaScript, Jasmine, and production code

I'm trying to grasp the basics of Jasmine (and BDD/TDD I guess). The examples I have seen does not resemble any realistic scenario of a web application, and have a hard time relating to it.
Are Jasmine tests done aside (separately) from working on the JavaScript that will be deployed? Manually copying tested/validated code.. Or does Jasmine compile to standard JS used for production?
Cheers
Jasmine is a framework for testing JavaScript code. Just like testing Ruby on Rails code, the tests don't become part of the production code. They are in the same repo and are run but they aren't minified into project.js or whatever your build process is. As part of your test run process, you can do headless tests using PhantomJS (headless webkit) and have it run on your CI server and so forth just like any other test.
I have worked on a bunch of projects this way. There has been a trend of seeing JavaScript has an enhancement layer that doesn't really need to be tested but today JavaScript is so much more. It is critical to test it if your application needs to work.

How do I unit test JavaScript using nUnit?

I would like to run unit tests of my JavaScript code in Cruise Control. We currently use nUnit, and I see that nUnit has a javascript library. How do I write unit (not UI) tests in JavaScript using nUnit?
The best way to automate JS tests and include them in continuous integration process is to use JSTestDriver. It is very fast, can test your scripts in all kinds of browsers, can be easily integrated in IDE (How To ntegrate JsTestDriver in Visual Studio), and what is more important - this is simple comsole application, which can be easily be executed from nant script.
The example of solution with JsTestDriver tests is here.
You can do this with JSUnit. Their JSUnit Server allows you to run scriptable JavaScript unit tests within a Java virtual machine (JVM).
You can use Rhino, which is a Javascript runtime written in Java (IIRC, the command-line is something like java -jar Rhino.jar script.js).
This is especially useful if your tests don't require a browser.
Don't forget to analyze your JS code with JSLint !

Categories

Resources