Selenium Code Coverage for Java Web Applications
In this 4mins video, you will see how to generate selenium code coverage for web application developed with Java in eclipse ide using RKTracer Tool with 3 simple steps.
- Enable the RKTracer tool and rebuild the application.
- Test instrumented application and save coverage data.
- Generate code coverage reports
Code Coverage tool integration with Eclipse IDE
1: Close all instances of Eclipse IDE.
2: Open a new command prompt and run the following command to install the RKTracer tool plugin for eclipse IDE.
rktracer -ec -integrate
Once successfully RKTracer tool is integrated with Eclipse IDE. You can see RKTracer tool options in Run menu–> External tools
Selenium Code Coverage for Java based Web Application
Ensure that you’re able to build the application and run the selenium tests.
Enable the RKTracer tool
Select the project in eclipse in the project explorer and enable the RKTracer tool.
Run–> External Tools –> RKTracer ON
Rebuild and run selenium tests
Run maven clean and maven test to build web application and run selenium tests. In general, testing can be unit testing or functional testing.
Generate Code Coverage reports
Go to –>Run menu–> External Tools –> RKTracer Report.
Enable coverage for selected files
Generate coverage reports for the selected folders
Suppose you need code coverage for source files from three different folders, i.e., core, keys, power, and ignore coverage for folders firmware_loader and lockdown. Edit rktracer.config in the RKTracer installation folder and go to the end of the file add the following information.
instrument */power/* */core/* */keys/*
never */firmware_loader/* */lockdown/*
ignore *.java = Ignores all Java source files from instrumentation
Instrument = Instrument source files from given folders
never = ignore selected folder
Generate coverage reports only for selected functions from three different files.
fun_X() in source-file-X
fun_Y() in source-file-Y
fun_Z() in source-file-Z
Suppose you need code coverage for selected functions from three different files. Edit rktracer.config in the RKTracer installation folder and go to the end of the file and set the following variables as shown below.
instrument *source-file-X.java *source-file-Y.java *source-file-Z.java
function-instrument fun_X() fun_Y() fun_Z()
ignore *.java = Ignore all Java programming source files
instrument *file-X.java *file-Y.java *file-Z.java = Instrument only these three source files.
function-ignore * = Then ignore all functions in the above three files.function-instrument fun_X() fun_Y() fun_Z() = Don’t ignore these three functions from these three files from instrumentation