From: Harish P. <hpr...@co...> - 2005-05-18 16:01:21
|
hi, We are trying to merge two cobertura.ser files which has the same code base. one cobertura.ser files is created when running junit and the other is created when weblogic server is stopped which are created in two different directories. Apparently when trying to merge we found that it is just overwriting the other. for e.g. Junit calls a Delegate class which happens to have a code coverage of 40%. This Delegate class calls the server classes and no Delegate class is called through the server. So the code coverage for this Delegate class is 0% in the cobertura.ser generated by the weblogic. Now when we are trying to merge this both ideally it should been given 40% but it gives 0%. Going through the source code we found that in CoverageData.java we have a method which merges the two files as given below. public void merge(CoverageData coverageData) { lines.putAll(coverageData.lines); conditionals.putAll(coverageData.conditionals); methodNamesAndDescriptors.addAll(coverageData .getMethodNamesAndDescriptors()); } In the above code lines is a HashMap object The lines.putAll(coverageData.lines) just overwrites the data. The above method could be modified as given below. public void merge(CoverageData coverageData) { Set keySet = lines. keySet(); Iterator iterator = keySet.iterator(); while(iterator.hasNext()) { Integer lineNumber = (Integer) iterator.next(); LineInformation l1 = (LineInformation)lines.get(lineNumber); LineInformation l2 = (LineInformation)coverageData.lines.get(lineNumber); long hits1 = l1.getHits(); long hits2 = l2.getHits(); if(hits2>hits1) { lines.put(lineNumber,l2); } } //lines.putAll(coverageData.lines); conditionals.putAll(coverageData.conditionals); methodNamesAndDescriptors.addAll(coverageData .getMethodNamesAndDescriptors()); } Let me know if anyone has a better solution. Regards Harish > -----Original Message----- > From: Harish Prabhakara > Sent: Tuesday, May 17, 2005 4:04 PM > To: 'cob...@li...' > Cc: Iyer, Tejas; Satyadarshi Mishra; Bothra, Naveen > Subject: improper codecoverage report > > hi, > > We are trying to do a code coverage analysis for an application deployed > under Weblogic 8.1 server. The application is been tested > using Junit as well as HttpUnit Test Cases. While doing the code coverage > analysis we found that the code coverage is been > reported for those classes which has been called through Junit. Code > coverage for those Classes which are run under Weblogic > environment or under HttpUnit environment is not shown as covered. For > E.g. Let us say that we have got a Delegate class > which calls a service. This service is an EJB which is been deployed in > the Weblogic server. This Ejb in turns calls some VOAssembler > classes and in turn calls the DAO classes. > > > The test case calls the SiteDelegate which internally finds the service > and executes the service. > > The build.xml does exactly as mentioned in the documentation. > > set the classpath for the cobertura.jar. > compile the java files. > Create instrumented classes over the compilation classes > set the classpath for the instrumented classes > run the testcase > create the report. > > On analysis of the report, we could find code coverage only for delegate > class and there no coverage is been reported for other classes such > as EJB, VOAssembler and DAO. > > > Kindly can you help in resolving this problem. > > Thanks and Regards > Harish > |