Mercurial > hg > MauveTestCoverage
changeset 10:4a18f35c8dff
2012-02-03 Pavel Tisnovsky <ptisnovs@redhat.com>
* src/ReportGenerator.java:
Added new functionality: table with number of all methods
and methods coveraged by the test are used in the
generated page with all packages list.
Added generation of links to external JavaDoc
for packages and classes.
* templates/all_packages_template.html:
Changed table column names to be more consistent
with the rest of the report system.
* templates/index.html:
Updated width of left column to 25% from 20%.
* templates/style.css:
New styles used by all_classes_list.html.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Fri, 03 Feb 2012 17:39:45 +0100 |
parents | 5bc6733b29bd |
children | f010a4361c96 |
files | ChangeLog src/ReportGenerator.java templates/all_packages_template.html templates/index.html templates/style.css |
diffstat | 5 files changed, 80 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Feb 01 10:24:45 2012 +0100 +++ b/ChangeLog Fri Feb 03 17:39:45 2012 +0100 @@ -1,3 +1,19 @@ +2012-02-03 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/ReportGenerator.java: + Added new functionality: table with number of all methods + and methods coveraged by the test are used in the + generated page with all packages list. + Added generation of links to external JavaDoc + for packages and classes. + * templates/all_packages_template.html: + Changed table column names to be more consistent + with the rest of the report system. + * templates/index.html: + Updated width of left column to 25% from 20%. + * templates/style.css: + New styles used by all_classes_list.html. + 2012-02-01 Pavel Tisnovsky <ptisnovs@redhat.com> * src/ReportGenerator.java:
--- a/src/ReportGenerator.java Wed Feb 01 10:24:45 2012 +0100 +++ b/src/ReportGenerator.java Fri Feb 03 17:39:45 2012 +0100 @@ -57,6 +57,11 @@ public class ReportGenerator { /** + * Location of internal or external URI to standard API JavaDoc + */ + private static final String DOC_BASE = "http://docs.oracle.com/javase/6/docs/api"; + + /** * Read all classes from a file containing its list. * * @param allClassListFileName @@ -168,7 +173,7 @@ // replace text in template where needed if ("${PACKAGE_AND_CLASS_LIST}".equals(templateLine)) { - addPackageAndClassList(usedPackageNames, testedClasses, out); + addPackageAndClassList(reportDirectory, usedPackageNames, testedClasses, out); } // normal line else @@ -209,9 +214,12 @@ // -> in percent final float percentage = 100.0f*testedClassesCnt / allClassesCnt; // table row background color is based on percentual test coverage ration - String backgroundColor = generateTableRowBackground(percentage); - String str = String.format("<tr style='background-color:%s'><td><a target='ClassesListFrame' href='%s.html'>%s</a></td><td style='text-align:right'>%d</td><td style='text-align:right'>%d</td><td style='text-align:right'>%5.1f %%</td></tr>", - backgroundColor, packageName, packageName, allClassesCnt, testedClassesCnt, percentage); + String backgroundColor = generateTableRowBackground(percentage); + String doc = DOC_BASE + "/" + packageName.replace('.', '/') + "/package-summary.html"; + // format output string + String str = String.format("<tr style='background-color:%s'><td><a target='ClassesListFrame' href='%s.html'>%s</a></td><td style='text-align:right'>%d</td><td style='text-align:right'>%d</td><td style='text-align:right'>%5.1f %%</td><td style='text-align:right'><a href='%s' target='_blank'>ext</a></td></tr>", + backgroundColor, packageName, packageName, + allClassesCnt, testedClassesCnt, percentage, doc); out.add(str); } } @@ -285,6 +293,8 @@ * Add list of all packages and all its classes to a list of string which * represents generated report. * + * @param reportDirectory + * directory where report is generated * @param usedPackageNames * all checked package names * @param testedClasses @@ -292,20 +302,38 @@ * @param out * list of string which represents generated report */ - private static void addPackageAndClassList(Set<String> usedPackageNames, Set<String> testedClasses, List<String> out) + private static void addPackageAndClassList(String reportDirectory, Set<String> usedPackageNames, Set<String> testedClasses, List<String> out) { // iterate through all class names for (String packageName : usedPackageNames) { out.add("<h2>Package " + packageName + "</h2>"); + out.add("<table class='classes_list'>"); + out.add("<tr><th>class</th><th>methods</th><th>covered</th><th>ratio</th><th>doc</th></tr>"); + http://docs.oracle.com/javase/6/docs/api/java/math/BigDecimal.html for (String className : testedClasses) { if (className.startsWith(packageName)) { - out.add("<a target='ResultsFrame' href='" + className + ".html'>" + className + "</a><br />"); + Set<String> apiMethods = readApiMethods(reportDirectory, className); + Set<String> testedMethods = readTestedMethods(reportDirectory, className); + // compute number of all methods in a class + final int allMethodsCnt = apiMethods.size(); + // compute number of methods covered by tests + final int testedMethodsCnt = testedMethods.size(); + // -> in percent + final float percentage = 100.0f*testedMethodsCnt / allMethodsCnt; + // table row background color is based on percentual test coverage ration + String backgroundColor = generateTableRowBackground(percentage); + String doc = DOC_BASE + "/" + className.replace('.', '/') + ".html"; + // format output string + String outStr = String.format("<tr style='background-color:%s'><td><a target='ResultsFrame' href='%s.html'>%s</a></td><td style='text-align:right'>%d</td><td style='text-align:right'>%d</td><td style='text-align:right'>%5.1f %%</td><td style='text-align:right'><a href='%s' target='_blank'>ext</a></td></tr>", + backgroundColor, className, className, + allMethodsCnt, testedMethodsCnt, percentage, doc); + out.add(outStr); } } - out.add("<br />"); + out.add("</table>"); } } @@ -448,6 +476,7 @@ private static void printReportForAllPackages(String reportDirectory, Set<String> usedPackageNames, Set<String> testedClasses) { + // iterate through all tested package names for (String packageName : usedPackageNames) { printReportForPackageToFile(reportDirectory, packageName, testedClasses); @@ -456,6 +485,7 @@ private static void printReportForAllClasses(String reportDirectory, Set<String> testedClasses) { + // iterate through all tested classes for (String testedClass : testedClasses) { Set<String> apiMethods = readApiMethods(reportDirectory, testedClass);
--- a/templates/all_packages_template.html Wed Feb 01 10:24:45 2012 +0100 +++ b/templates/all_packages_template.html Fri Feb 03 17:39:45 2012 +0100 @@ -11,7 +11,7 @@ <h1>Package list</h1> <a target='ClassesListFrame' href='all_classes.html'>all classes</a><br /><br /> <table class='package_list'> -<tr><th>Package</th><th>Classes</th><th>Covered</th><th>Ratio</th></tr> +<tr><th>package</th><th>classes</th><th>covered</th><th>ratio</th><th>doc</th></tr> ${PACKAGE_LIST} </table> </body>
--- a/templates/index.html Wed Feb 01 10:24:45 2012 +0100 +++ b/templates/index.html Fri Feb 03 17:39:45 2012 +0100 @@ -3,7 +3,7 @@ <head> <title>Test coverage report</title> </head> - <frameset cols="20%,80%" title=""> + <frameset cols="25%,75%" title=""> <frameset rows="40%,60%" title=""> <frame src="all_packages.html" name="PackageListFrame" title="Package List" scrolling="yes"> <frame src="all_classes.html" name="ClassesListFrame" title="All public classes" scrolling="yes">
--- a/templates/style.css Wed Feb 01 10:24:45 2012 +0100 +++ b/templates/style.css Fri Feb 03 17:39:45 2012 +0100 @@ -51,3 +51,28 @@ /* -moz-border-radius: ; */ } +table.classes_list { + border-width: 0px; + border-spacing: 0px; + border-style: dashed; + border-color: black; + border-collapse: collapse; + background-color: white; + width: 100%; +} +table.classes_list th { + border-width: 1px; + padding: 1px; + border-style: inset; + border-color: gray; + background-color: #c0c0ff; + /* -moz-border-radius: ; */ +} +table.classes_list td { + border-width: 1px; + padding: 1px; + border-style: inset; + border-color: gray; + /* -moz-border-radius: ; */ +} +