This guide shows how to generate Selenium code coverage for a web application developed with Java in Eclipse IDE using the RKTracer tool, with 3 simple steps:
- Enable the RKTracer tool and rebuild the application.
- Test the instrumented application and save the coverage data.
- Generate the code coverage reports.
Ensure that you're able to build the application and run the Selenium tests.
Integrate the RKTracer plugin with Eclipse IDE, turn RKTracer ON from Run, External Tools, run maven clean and maven test, then generate the report from Run, External Tools, RKTracer Report.
Code Coverage tool integration with Eclipse IDE
Integrate the RKTracer tool with Eclipse IDE before you build and run your Selenium tests.
- Close all instances of Eclipse IDE.
- Open a new command prompt and run the following command to install the RKTracer tool plugin for Eclipse IDE:
rktracer -ec -integrate
Once the RKTracer tool is successfully integrated with Eclipse IDE, you can see the RKTracer tool options in the Run menu, under External Tools.
Enable the RKTracer tool
Enable the RKTracer tool from the Eclipse IDE Run menu:
Run > External Tools > RKTracer ON
Rebuild and run selenium tests
Run maven clean and maven test to build the web application and run the Selenium tests. In general, testing can be unit testing or functional testing.
Generate Code Coverage reports
Generate the code coverage reports from the Eclipse IDE Run menu:
Run > External Tools > RKTracer Report
Enable coverage for selected files
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 and add the following information.
ignore *.java instrument */power/* */core/* */keys/* never */firmware_loader/* */lockdown/*
ignore *.javaignores all Java source files from instrumentation.instrumentinstruments source files from the given folders.neverignores the selected folder.
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.
ignore *.java instrument *source-file-X.java *source-file-Y.java *source-file-Z.java function-ignore * function-instrument fun_X() fun_Y() fun_Z()