You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 7 Members of 4087 |
| Forum: Seam Users |
23. Apr 2008, 06:11 CET | Link |
Hello,
I have a maven ear project (based the attchement at on http://jira.jboss.org/jira/browse/JBSEAM-2371). The structure is as follows:
project
project-ejb
project-web
project-ear
project-common
I have a bunch of SeamTest's in project-web that test Actions and EJB's in project-ejb. (having the tests in the web project makes it a lot easier to get the whole embedded setup running, see above link ) The test run OK (it was a bitch to get there...) but since the actions and EJBs are in the project-ejb.jar, I get no coverage.
Does anyone have an idea how to get and coverage for the actions and EJBs (in project-ejb) when running the SeamTest's (in project-web)? An example would be great, but any ideas are welcome. BTW, simply unjarring the project.ejb.jar in project-web/target-classes does not work.
Cobertura has to instrument your classes in order to capture code coverage data. When used with Maven and executing the command:
a directory is created for each sub-project:
These are the classes that must be in your classpath to generate code coverage analysis. You could try jarring up the generated classes and using the instrumented jars when running SeamTest. Should work, but I haven't tried it so no guarantees ;)
Hope that helps.
--------------------------------------------------
Check my blog to find announcements on Seam Framework: Experience the Evolution of Java EE
Thanks. I'll try that tomorrow (or is it today already...)
I was thinking that classes have to be instrumented 'in place', that is within the web project. That doesn't seem to be the case :)
Sound like it should work, I'll just need to come up with some script (ant?) to get it automated.
Yes, Ant is probably going to be your best bet for the script. Let me know how it goes. I'm sure the community would be quite appreciative if you wanted to contribute the script. I know I would :)
--------------------------------------------------
Check my blog to find announcements on Seam Framework: Experience the Evolution of Java EE
I managed to get it to work following Jacob's suggestion. Thanks a lot. I haven't had the time to automated (next week, hopefully...), but here are the steps I took:
6. generate coberura report in project-web
Steps 5 and 6 are necessary because coberutra:cobertura runs the test twice and the second time they fail. It seems the classpath differs(?) and jboss embedded fails to start; haven't had the time to dig into it, but might be related to http://jira.codehaus.org/browse/SUREFIRE-257?
Thanks again.
You could try to redirect output of cobertura to the regular target/classes, see configuration of the cobertura-maven-plugin but then you will have danger of packaging instrumented classes to your production packaging. Even then instrumented classes will need to be in a jar, I am not sure whether cobertura can handle instrumented classes from jars...
To be honest cobertura (at least if run via maven plugin) is not really a integration test coverage tool (but a 'simple' unit test coverage tool). I think you might have a look at clover for integration tests coverage (in case you can afford to pay or you're busy with OSS).
There were some talks on maven mail lists about enabling integration testing but afaik the discussions didn't go far...
For more reference check this and this out.
I have a feeling this whole situation with maven may require writing a special seam plugin (too many issues)...
Regards,
Siarhei
It seems instrumented jars work OK, so I might try that out. Should be cleaner that messing with ant. I could have a separate profile for testing and that should eliminate the danger of packaging instrumented classes in prodcution.
We have used clover before (the very first release) and it worked OK. I guess we could afford it but that could take some time. Anyways, thanks for the suggestion, I'll check it out. (sometime...)
That would be really nice. Seam is great but testing is ..., well, not for the faint of heart :)
BTW, thanks for the sample project at JBSEAM-2371, it was huge help!
This is quite an old thread, but since I've finally had a bit of time to look into it, I thought I'd share my findings.
The maven cobertura task is not flexible enough to handle multiple projects (there is no way to specify source folders, aggregate coverage, etc.; there are a few pending FR's about that), so I ended up using the ant tasks in my maven project. I defined a profile that aggregates the ejb module coverage with the SeamTests coverage (in the web module) and creates a report.
How to use:
Here is the profile:
<profile> <id>coverage</id> <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <dependencies> <dependency> <groupId>net.sourceforge.cobertura</groupId> <artifactId>cobertura</artifactId> <version>1.9</version> </dependency> </dependencies> <executions> <execution> <phase>process-test-classes</phase> <id>instrument-ejb-jar</id> <configuration> <tasks> <taskdef classpathref="maven.runtime.classpath" resource="tasks.properties" /> <mkdir dir="${project.build.directory}/cobertura" /> <copy todir="${project.build.directory}/cobertura"> <fileset dir="../project-ejb/target/cobertura" /> </copy> <copy file="${settings.localRepository}/org/foobar/project-ejb/${project.version}/project-ejb-${project.version}.jar" tofile="${settings.localRepository}/org/foobar/project-ejb/${project.version}/project-ejb-${project.version}.jar.org" /> <cobertura-instrument> <includeClasses regex=".*" /> <excludeClasses regex=".*\DontLikeInstrumentation.*" /> <instrumentationClasspath> <pathelement location="${settings.localRepository}/org/foobar/project-ejb/${project.version}/project-ejb-${project.version}.jar" /> </instrumentationClasspath> <!-- or use this:--> <!-- <fileset dir="${settings.localRepository}/org/foobar/project-ejb/${project.version}"> <include name="project-ejb-${project.version}.jar" /> </fileset> --> </cobertura-instrument> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> <execution> <phase>integration-test</phase> <id>cobertura-report</id> <configuration> <tasks> <taskdef classpathref="maven.runtime.classpath" resource="tasks.properties" /> <mkdir dir="${project.build.directory}/site/cobertura" /> <cobertura-report format="html" datafile="${project.build.directory}/cobertura/cobertura.ser" destdir="${project.build.directory}/site/cobertura"> <fileset dir="${basedir}/src/main/java"> <include name="**/*.java" /> </fileset> <fileset dir="../project-ejb/src/main/java"> <include name="**/*.java" /> </fileset> </cobertura-report> <copy overwrite="true" file="${settings.localRepository}/org/foobar/project-ejb/${project.version}/project-ejb-${project.version}.jar.org" tofile="${settings.localRepository}/org/foobar/project-ejb/${project.version}/project-ejb-${project.version}.jar" /> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile>Mind adding that to the knowledge base?
Done.
SeamTest Coverage with Cobertura