Feeds:
Posts
Comments

Archive for the ‘Technology’ Category

Cobertura – FAQ

Q: Where does the name “Cobertura” come from?

A: “Cobertura” is the Spanish and Portuguese word for “coverage.”
We were trying to avoid acronyms and coffee references.
It’s not too hard to associate the word “cobertura” with the word “coverage,”
and it even has a bit of a zesty kick to it!

Q: Why should I use Cobertura instead of one of the other code coverage tools?

A: We think Cobertura produces the prettiest output.
Pretty output means it’s easy to read. Easy to read means you waste less time figuring out
where to add test coverage. We also think Cobertura is easy to get running.

Q: What about Emma?

A: We haven’t used it very much, but it looks like it does a pretty good job.
Judging from the sample on the Emma web page, we think the Cobertura HTML reports
are a bit easier to digest. It looks like Emma has some nice usability features,
such as the ability to instrument all classes in a jar file with one command.
A little friendly competition never hurt anyone

Q: What do I need to use Cobertura?

A: Cobertura should work on any platform with with Java 5 or newer.
The Cobertura download packages include all the dependencies you’ll need (ASM, log4j, etc.)
Q: What is code complexity and why should I care about it?
A: McCabe’s cyclomatic code complexity algorithm is used to determine how “complex” a given piece of code is. As code becomes more complex, it becomes more error prone. If a class has a high complexity number, then that class is a good target for additional test coverage.
Q: Why is Cobertura causing me to have classpath conflicts with ASM?
A:Cobertura uses ASM to modify your bytecode. There are a few other popular programs that use ASM; Groovy and Hibernate, to name two.
You could have problems if Cobertura uses a different version of asm and you add both versions to your classpath.
Cobertura only uses ASM when instrumenting. Cobertura does not need ASM in your classpath when running tests.
If you’re seeing classpath conflicts, just make sure the asm jar that comes with Cobertura is used only by Cobertura, and only when instrumenting.
Usage:

  • When I generate coverage reports, why do they always show 100% coverage everywhere?
  • When I generate coverage reports, why do they always show 0% coverage everywhere?
  • Cobertura is probably using the wrong .ser file when generating the reports.
  • When you instrument your classes, Cobertura generates a .ser file containing basic information about each class.
  • As your tests run, Cobertura adds additional information to this same data file.
  • If the instrumented classes can not find the data file when running then they will create a new one.
  • It is important that you use the same cobertura.ser file when instrumenting, running, and generating reports.
  • The best way to do this is to specify the location of the data file when running your tests.

You should pass the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser sysproperty to the JUnit task

These are main steps to be used for Cobertura Reports.

  1. First Download Cobertura 1.9.2 jar and put in your local file system and extract it.
  1. Then create jars( lib, bridge, ejb ) for your project using Ant or eclipse.
  2. Copy these src jars into your cobertura folder ( example : D:\Cobertura\cobertura-1.9.2\ )
  3. Instrument the project jars using
  1. cobertura-instrument.bat <path to lib jar> <path to lib_bridge jar> <path to EJB jar>
  1. All the project jars would now be instrumented with the cobertura code along with the creation of cobertura.ser file in the same directory.
  2. Then deploy the jars in your development server.
  3. You should also add the cobertura.jar in the classpath(BE,FE/IN depending on your project’s nature).
  4. Copy the cobertura.ser to the server and in the startManagedWebLogic.sh, add the below system property
  1. -Dnet.sourceforge.cobertura.datafile=${directory where you have copied the cobertura.ser}/cobertura.ser
  1. Fire your Selenium test cases either through Firefox(Selenium IDE) or using Selenium Remote Control. Or else run your application by manually
  2. Shutdown the development server using WL Admin console and copy the cobertura.ser file back to the local cobertura folder.
  3. Run the cobertura report using
  1. cobertura-report.bat –destination <Output folder for reports> <List down the source folders(lib,lib_bridge,ejb) separated by ;>

9. Now you can check your local folder output folder Index.jsp

Read Full Post »

Object Serialization:-

What?
Serialization is a process of storing the object instance to a disk file. Serialization stores state of the object i.e. member variable values to disk.
Deserialization is reverse of serialization i.e. it’s a process of reading objects from a file where they have been stored.

Object serialization is the process of saving an object’s state to a sequence of bytes, as well as the process of rebuilding those bytes into a live object at some future time. The
Java Serialization API provides a standard mechanism for developers to handle object serialization.
The API is small and easy to use, provided the classes and methods are understood.

Why?
This mechanism has been added into the Java language for mainly two reasons:

  • the JavaBeans mechanism makes heavy use of serialization
  • remote method invocation (RMI) allows us to automatically use objects located at another host in the network just like any local objects.

How ?

==================================================================================================================================================
package lib;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ObjectSerialization {

public static void main(String[] args) {

try {

//Create a file to write the serialized tree to.
FileOutputStream ostream = new FileOutputStream(“tree.txt”);
//Create the output stream
ObjectOutputStream p = new ObjectOutputStream(ostream);

//Object ceations with serializable
Tree tree = new Tree();
tree.setName(“123Kumar345Adyar”);

//Create a tree with three levels.
//Write the tree to the stream.
p.writeObject(tree);

p.flush();
ostream.close();
//close the file.

//Open the file and set to read objects from it.
FileInputStream istream = new FileInputStream(“tree.txt”);
ObjectInputStream q = new ObjectInputStream(istream);

// Read a tree object, and all the subtrees */
Tree new_tree = (Tree)q.readObject();

System.out.println(” *** “+new_tree.getName());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

Thanks & Regards,
Rajeshkumar. E |

Read Full Post »