# HG changeset patch # User Pavel Tisnovsky # Date 1330703477 -3600 # Node ID 5030a59cd546c37bd0a63c300627da02c31018d7 # Parent f010a4361c966896a9b85e7e223ebc101a661bed 2012-03-02 Pavel Tisnovsky * src/ReportGenerator.java: * templates/package_template.html: Added new functionality of report generator: table with basic statistic is shown for each tested package. diff -r f010a4361c96 -r 5030a59cd546 ChangeLog --- a/ChangeLog Tue Feb 21 17:16:21 2012 +0100 +++ b/ChangeLog Fri Mar 02 16:51:17 2012 +0100 @@ -1,3 +1,11 @@ +2012-03-02 Pavel Tisnovsky + + * src/ReportGenerator.java: + * templates/package_template.html: + Added new functionality of report generator: + table with basic statistic is shown for + each tested package. + 2012-02-21 Pavel Tisnovsky * src/FileUtils.java: diff -r f010a4361c96 -r 5030a59cd546 src/ReportGenerator.java --- a/src/ReportGenerator.java Tue Feb 21 17:16:21 2012 +0100 +++ b/src/ReportGenerator.java Fri Mar 02 16:51:17 2012 +0100 @@ -136,7 +136,9 @@ private static void printReportForPackageToFile(String reportDirectory, String packageName, Set testedClasses) { + // read HTML template List template = FileUtils.readTextFile("templates/package_template.html"); + // list containing all lines of generated HTML file List out = new LinkedList(); // iterate through whole template for (String templateLine : template) @@ -144,7 +146,11 @@ // replace text in template where needed if ("${CLASS_LIST}".equals(templateLine)) { - addClassList(packageName, testedClasses, out); + addClassList(reportDirectory, packageName, testedClasses, out); + } + else if ("${PACKAGE_NAME}".equals(templateLine)) + { + out.add("Package " + packageName); } // normal line else @@ -282,7 +288,7 @@ * @param out * list of string which represents generated report */ - private static void addClassList(String packageName, Set testedClasses, List out) + private static void addClassList(String reportDirectory, String packageName, Set testedClasses, List out) { // iterate through all class names for (String className : testedClasses) @@ -290,7 +296,8 @@ // list only classes from given package if (className.startsWith(packageName)) { - out.add("" + className + "
"); + //out.add("" + className + "
"); + out.add(addOneRowToResultsTable(reportDirectory, className)); } } } @@ -321,22 +328,7 @@ { if (className.startsWith(packageName)) { - Set apiMethods = readApiMethods(reportDirectory, className); - Set 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("%s%d%d%5.1f %%ext", - backgroundColor, className, className, - allMethodsCnt, testedMethodsCnt, percentage, doc); - out.add(outStr); + out.add(addOneRowToResultsTable(reportDirectory, className)); } } out.add(""); @@ -344,6 +336,34 @@ } /** + * Add one row to a table containing test coverage for given class. + * + * @param reportDirectory + * directory where report is generated + * @param className + * name of tested class + */ + private static String addOneRowToResultsTable(String reportDirectory, String className) + { + Set apiMethods = readApiMethods(reportDirectory, className); + Set 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("%s%d%d%5.1f %%ext", + backgroundColor, className, className, + Integer.valueOf(allMethodsCnt), Integer.valueOf(testedMethodsCnt), Float.valueOf(percentage), doc); + return outStr; + } + + /** * Create new HTML file containing report for one tested class. * * @param reportDirectory @@ -479,6 +499,17 @@ return out; } + /** + * Create report for all packages. For each package, one package-name.html + * file is created containing table with basic coverage report. + * + * @param reportDirectory + * directory where report is generated + * @param usedPackageNames + * packages for which the report is generated + * @param testedClasses + * set of tested classes + */ private static void printReportForAllPackages(String reportDirectory, Set usedPackageNames, Set testedClasses) { @@ -625,6 +656,13 @@ return String.format("%.2f%%", ratio); } + /** + * Prepare whole report - HTML and txt one. + * + * @param allClassListFileName + * @param testedClassListFileName + * @param reportDirectory + */ private static void prepareReport(String allClassListFileName, String testedClassListFileName, String reportDirectory) { diff -r f010a4361c96 -r 5030a59cd546 templates/package_template.html --- a/templates/package_template.html Tue Feb 21 17:16:21 2012 +0100 +++ b/templates/package_template.html Fri Mar 02 16:51:17 2012 +0100 @@ -9,7 +9,13 @@

Class list

+

+${PACKAGE_NAME} +

+ + ${CLASS_LIST} +
classmethodscoveredratiodoc